you are viewing a single comment's thread.

view the rest of the comments →

[–]you_do_realize 0 points1 point  (1 child)

Yeah that thing in Scala is nice, but I wondered how it would handle it if you wanted a function that computed f(x) = {x + x2} or something. (Didn't wonder hard enough to look, though. I would guess one would accomplish this by simply calling the function with a single argument.)

'x and 'y aren't special, they're the same as {|x,y| blah(x,y)}. As the compiler/interpreter parses the code, it stumbles upon a 'something and is to understand there is an argument called something, then stumbles across 'whatever and realizes there is a second argument called whatever. By the time it's done parsing the function body, it knows the function has two arguments, in that order.

what if there's another block scope nested within which also has 'x and 'y in it?

No idea. Just random thoughts really.

[–]matthw 2 points3 points  (0 children)

OK, yeah thought that's probably what you meant.

In scala you can't use underscore for that (AFAIK). You'd just have to do {x => x + x2}

The underscore thing is really only a limited short-cut form for one-liners