[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: call/cc



kragen@pobox.com (Kragen Sitaker) writes:

[...]

> > in fact, (+) is the same as (\x y -> x + y) via eta-reduction.
> 
> Yes, and (+) 3 5 is the same as 8 via constant folding and function
> application.  But '8' is not a useful answer to the question, "How do
> I add two numbers in OCaml?"

i thought you included the calling part to count the number of tokens it took.
Once again you wanted something adding 2 parameters, not adding 3 and 5 ;pp

> 
> > Anyway, you can have the same as your stack-based construct in other
> > languages:
> > 
> > Lisp's (funcall '+ 3 5)
> 
> That isn't the same; that calls + directly (well, actually, it calls
> it after looking up its function binding in the environment).  {add}
> or :noname + ; or [+] are freshly-created lambda-expressions that
> simply call + themselves, but are not themselves identical to +.

i still don't agree, but hey, that's how it goes :)

> 
> > but this is pretty dumb... Maybe a better closure example would be better.
> > What about adding the 2 parameters + 1.
> 
> These aren't closures, FWIW.

oops. typo

[...]

> > Haskell: (\x y -> x + y + 1) 3 5         12 tokens
> > FORTH, PostScript, dc???
> 
> 
> PostScript: 3 5 {add 1 add} exec     8 tokens
> dc: 3 5 [+1+] x                      8 tokens
> FORTH: 3 5 :noname + 1+ ; execute    7 tokens

wow nice.

haskell could also be

((+) . ((+) 1)) 3 5      

but since it's longer than the readable version (14 vs 12 tokens), i can't
fight anymore against stack-languages :)


merd version:

- add 2 numbers:
(+)(3, 5)      8 tokens  (where (+) *really* is sugar for "x,y -> x+y")

- add 2 numbers + 1:
(x, y -> x + y + 1)(3, 5)   16 tokens
((1 +) ~ (+))(3, 5)         15 tokens

(all space are optional)

PS: http://merd.net/