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 20:39

>>1
I seem to recall reading something stating let being short for lambda-something.

One thing I have stuck by though is having been introduced to let in terms of lambdas, and equivalence is fairly important to me. JS is still pretty good though, if you keep in mind the edges are quite jagged.

>>6
FIOC doesn't even have lambda-lambda equivalence.

>>15
I hear people use that sorry excuse all the time. It's nonsense though. With a self-recursive operation (especially one that equates to iteration) there is no reason to add yet more calls onto the stack trace. You don't record every pass through a loop construct after all.

For mutually recursive functions, I just think of it as factoring the case analysis bodies out of the main function. If your language has letrec then it's made clear what system of functions you're in anyway.

>>18
No one said that, but it is funny. Yet it's more sad than funny. The more powerful things are eschewed (ever write a state machine without recursion—bleh) to afford the opportunity to include ever more garbage I don't want to read when the program crashes.

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