What then, is b?
(This was going to be an article about how impossible it is to design one language that has all my favourite features. But instead, became a scene from "A Coder's Edition of Saw.")
You wake up, in unfamiliar surroundings.
You must've experienced some kind of memory loss because you have no idea how you got to where you are. Your forehead is brittle with dried blood.
In front of you is a computer screen, and on the screen it says:
a = Add(2,3);
//a is 5.
b = Add(2);
//what is b?
Intriguing. What is b?
Because you're uncertain of the language in question, you can't be sure.
It could be that Add is an overloaded function, in which case b would be an integer. Its exact value is anyone's guess.
Or it could be that Add has an optional second parameter. Again b would be an integer, though its value could be anything.
It could be that the code refuses to run. The missing parameter is a deal breaker.
But you look at the tattoo on the back of your hand, the 11th letter of the greek alphabet, and you are certain.
What then, is b?
'Tommy' on Sun, 18 Jul 2010 12:20:32 GMT, sez: b is a function that adds 2 to its argument.
'Richard Mason' on Sun, 18 Jul 2010 12:27:20 GMT, sez: I thought it was more the smell of vindaloo on his breath that gave it away.
'Huseyin Tufekcilerli' on Sun, 18 Jul 2010 12:30:08 GMT, sez: b is 42
'OJ' on Sun, 18 Jul 2010 12:31:29 GMT, sez: One side of me says it's a partially applied function waiting for a number to add to 2.
The other side of me is telling me to stop playing spin the bottle with Neo.
'kokokrunch' on Sun, 18 Jul 2010 13:15:32 GMT, sez: b is 2
'Shalom Craimer' on Sun, 18 Jul 2010 14:05:23 GMT, sez: "the 11th letter of the greek alphabet" ? That's a heavy-handed hint, sir!
Thanks for the laugh - that was fun!
(The article almost makes me yearn for a Zork-style story about a programmer coming-of-age or something.)
'tarun' on Sun, 18 Jul 2010 20:42:40 GMT, sez: I am with tommy on this one:
eleventh letter of greek alphabet is lambda.
hence applying lambda calculus (in particular currying) and we can see that b is a function that is just curried form of add(x,y) where b adds 2 to its argument.
'pizza' on Sun, 18 Jul 2010 23:01:32 GMT, sez: > let add x y = x + y
> add 2 3
5
> :type add
add :: (Num a) => a -> a -> a
> :type add 2
add 2 :: (Num t) => t -> t
> :type add 2 3
add 2 3 :: (Num t) => t
'Code Rant' on Fri, 23 Jul 2010 09:25:05 GMT, sez: You've been smoking that Haskell crack again.
'free promo codes' on Sat, 31 Jul 2010 14:42:21 GMT, sez: yes as you said its difficult to understand any unknown language and its true as well that all features cant be obtained in the same langauge
'Boyd Brown' on Fri, 10 Sep 2010 14:11:59 GMT, sez: b is 2
b = Add();
// b is 0.
(+ 2)
// returns 2.
(+)
// returns 0.
// it's greek...it's lambda...omg, it's lisp!
(+ 2 3 4)
// returns 9.
// out of the deep, dark, damp earth lisp is resurrected...clojure.org
'Coupon Codes' on Wed, 28 Sep 2011 05:29:25 GMT, sez: It's looking like a small thing. When enter in it...it's mind blowing..
'Ishpeck' on Fri, 14 Oct 2011 13:16:56 GMT, sez: b is a curried function. :P
b = Add(2)
c = b(2) // Now c is 4
|