Live data from Hacker News

PHP in a Tweet

emanueleminotto.it

51–58 of 58 posts

Re: PHP in a Tweet

#51
post #30

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

kudos. almost as cool as the cpp template hack to compute area based on part of the source code 'ascii art' size. (which I can't find anymore. googlefu--)

Re: PHP in a Tweet

#52
post #40

Earlier 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…

Gotcha, very interesting!

Re: PHP in a Tweet

#53
post #49
post #40

Earlier 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

I love that example, but it does depend upon some pretty arcane features in Haskell's type inference engine.

Re: PHP in a Tweet

#54
post #44
post #40

Earlier 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?

My hypothesis was that the compiler was tracking the arities of each function in order to open up opportunities for partial application. That means there's some ambiguity when you write something like (+ 1) which, in Scheme is a complete application equal to 1 but may also be interpreted as a partial application equal to (lambda (x) (+ 1 x)).

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

#55

I 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…

Here it is in Perl6:

  [+] ^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

#57
post #9

At 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! :)

Re: PHP in a Tweet

#58
post #9

At 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! :)

That was wonderful. Thank you! :D
Post reply on HN