Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let/lambda equivalence

Name: Anonymous 2012-08-13 20:54

Most call-by-value languages with anonymous functions have let/lambda equivalence: declarations are exactly the same as function parameters/arguments.
((lambda (i j) (* i j)) 3 4)
(let ((i 3) (j 4)) (* i j))


((INT i, j)INT: i * j)(3, 4)
(INT i = 3, j = 4; i * j)


(fn (i, j) => i * j)(3, 4)
let val (i, j) = (3, 4) in i * j end


A related rule is that any expression can be wrapped in a lambda without changing its meaning (besides grouping the expression). Notice how it is the expressions within the lambda bodies that create the scope in which the variables are bound and not the lambdas themselves.
((lambda () (let ((i 3) (j 4)) (* i j))))
INT: (INT i = 3, j = 4; i * j)
(fn () => let val (i, j) = (3, 4) in i * j end)()


One popular language does not follow these rules. Can you guess what it is? It's a language where certain constructs need to be wrapped in functions which are called immediately. It's supposedly ``Scheme-inspired'' but it's statement-based and uses a return keyword. The upcoming version will add a new type of function and variable that does follow these rules, at the expense of having two sets of rules and bloating the language beyond C++.
Give up? It's JavaScript.

Name: Anonymous 2012-09-18 23:16

>>23
dynamic scoping is shit. If you want to understand why, all you have to do is try to program using it. Then, then you'll see why it isn't that great of an idea for a function to behave differently based upon the environment it was called from, something that changes with every invocation and certainly can't be predicted at the time when you are writing the definition of the function.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List