Earlier quoted context omitted.
array_sum_of_1_2_3_4_5(); (Added in PHP 6)
the funny thing is, with proper abuse of __call you can almost get that to work: https://gist.github.com/kennethrapp/328b6bd1bda8a8f94092
PHP in a Tweet
51–58 of 58 posts
Re: PHP in a Tweet
#52Earlier quoted context omitted.
So it's tracking the arity of functions and turning anything which has been applied to fewer than ARITY arguments to a partial application? I suppose that comes at the cost of (+ 1 2 3 4)?
It does track the arity of functions, but remember that this happens at compile time. Regular addition in Pharen is still just regular addition in PHP: (def a (+ 1 2 3 4)) ; => $a = (1 + 2 + 3 + 4); Of course, there are situations where partial application won't always happen because the compiler is unable to detect it: (fn add (x y) (+ x y)) (map #add [1 2 3]) Pharen won't be able to realize that `add` here is being…
Re: PHP in a Tweet
#53Earlier quoted context omitted.
So it's tracking the arity of functions and turning anything which has been applied to fewer than ARITY arguments to a partial application? I suppose that comes at the cost of (+ 1 2 3 4)?
Surprisingly, not really. {-# OPTIONS -fglasgow-exts #-} class BuildList a r | r-> a where build' :: [a] -> a -> r instance BuildList a [a] where build' l x = reverse$ x:l instance BuildList a r => BuildList a (a->r) where build' l x y = build'(x:l) y varargs x = build' [] x main = print $ ( sum $ varargs 1 2 3 4 5 6 100) $ ./Test 121 http://okmij.org/ftp/Haskell/vararg-fn.lhs
Re: PHP in a Tweet
#54Earlier quoted context omitted.
So it's tracking the arity of functions and turning anything which has been applied to fewer than ARITY arguments to a partial application? I suppose that comes at the cost of (+ 1 2 3 4)?
Why would it?
There are many ways to mitigate that ambiguity statically and dynamically, but I feel there's always going to be a tradeoff between favoring partial application, favoring variadic functions, and the complexity/sophistication of your static checking or runtime environment.
I just made a stab at where the solution might lie in that design space. Turns out I was wrong.
Re: PHP in a Tweet
#55I enjoy PHP like I enjoy going home to see my family for the holidays. It's fun for a bit, the nostalgia makes me feel warm and fuzzy, and the familiarity of everything is very comforting. You quickly realize though that the grass really is a lot greener on the other side. You remember why you moved out of your parent's place and went out on your own. It's hilarious looking at how cryptic these one-liners are, partic…
[+] ^6
Actually cheated slightly because ^6 creates list from 0..5 :)So correct match would be...
[+] 1..5
Here's how you would do it in Io: list(1, 2, 3, 4, 5) reduce(+)
In Rebol there isn't a functional fold/reduce built in. So one way to do the one-liner would be: x: [1 2 3 4 5] forskip x 2 [insert x '+] x: do next x
Above changes x to 15. Alternatively approach which doesn't clobber x: x: [1 2 3 4 5] y: [] forall x [repend y [x/1 '+]] take/last y do y
I'm sure someone with more Rebol chops can see other (better!) ways of doing this :)Re: PHP in a Tweet
#56Re: PHP in a Tweet
#57At the risk of arousing some people's ire, I really like these tidbits that try to squeeze maximum functionality (albeit a bit dangerous) into a minimum span of characters. It feels a bit like the underhanded C contest in a way since there are so many magnificent ways to self-destruct doing this, but at the same time it's a fun challenge. A while ago, I put together a dirt-simple URL shortener https://twitter.com/eks…
Here's a fun(!) presentation of Rebmu given by Dr. Rebmuthalamonious Golfstanipetrovitch (!!) given at the recent Rebol/Red conference - http://www.youtube.com/watch?v=iDKaz1iB9wQ
Enjoy! :)
Re: PHP in a Tweet
#58At the risk of arousing some people's ire, I really like these tidbits that try to squeeze maximum functionality (albeit a bit dangerous) into a minimum span of characters. It feels a bit like the underhanded C contest in a way since there are so many magnificent ways to self-destruct doing this, but at the same time it's a fun challenge. A while ago, I put together a dirt-simple URL shortener https://twitter.com/eks…
You might find Rebmu interesting, its a Rebol dialect designed for code golfing - https://github.com/hostilefork/rebmu Here's a fun(!) presentation of Rebmu given by Dr. Rebmuthalamonious Golfstanipetrovitch (!!) given at the recent Rebol/Red conference - http://www.youtube.com/watch?v=iDKaz1iB9wQ Enjoy! :)