6 ms·
> I hated that in order to do a loop in a lambda, you had to implement a y-combinator, but they fixed that. Heh, I see what you did there.
by noblethrasher 8y ago
> I hated that in order to do a loop in a lambda, you had to implement a y-combinator, but they fixed that.
Heh, I see what you did there.
- lelf 8y agoIt's just fun(F)->fun(X)->F(fun(V)->X(X(V))end)end(fun(X)->F(fun(V)->X(X(V))end)end)end
- i_feel_great 8y agoThere's no fun reading that
- tombert 8y agoI actually didn't mean any kind of pun in this case; I actually meant the lambda-calculus Y combinator. Basically, Erlang doesn't allow loops, only recursion, which is fine for regular functions, since you can just use the function's name. However, anonymous functions inherently do not have a name, and as a result the only way to do loops is to whip out your textbook on Lambda Calculus, and copy Haskell Curry's way of doing recursion. It works fine, but it's also really hard to read, and not fun. Erlang 17 allowed you to give a temporary name to the lambda, which you could use for recursion.
- noblethrasher 8y agoYes, I knew that you were referring to the lambda calculus y-c. I've edited my original comment to make the pun more apparent.
- tombert 8y agoSilly me!
- slezakattack 8y agoI'm glad Erlang gave you the feature you were looking for but I can't help think of what the cases would be where a map, fold, or even assigning a lambda function to a variable wouldn't work?
- tombert 8y ago95% of the time, a fold or map are fine. Typically the reason that I use recursion explicitly is when I want to early-exit a loop. In imperative languages, that's trivial, just do a break or something, but in functional, that sort of goes against the point of a map or fold. Also, it's useful for any other particular reason you might need recursion (e.g. directory traversal) EDIT: In regards to assigning it to a variable, I don't believe that will work, since the naming comes after the fact. I could be wrong on that.
- slezakattack 8y agoThank you for the response. I totally agree on the early-exit loop problem