  lua-l archive

• Subject: Re: Lua Digest, Vol 78, Issue 2
• From: "Evan DeMond" <evan.demond@...>
• Date: Thu, 29 Nov 2007 09:11:52 -0500

On Nov 28, 2007 10:24 PM, KHMan <keinhong@gmail.com> wrote:
Vyacheslav Egorov wrote:
> KHMan wrote:
>> From the little I know or understand of lambda calculus, it's
> One can use  Y Combinator to implement recursion using only anonymous
> functions.
>
> local function Y(f)
>  function rec(...) return f(rec, ...) end
>  return rec
> end
>
> local fac = Y(function(fac, n) if n == 1 then return 1 else return fac(n
> - 1) * n end end)
>
>
> In fact one can turn Y in purely anonymous function. It is expensive,
> but possible. See Wikipedia or some good old book (e.g. Essentials of
> Programming Languages) for more details.

Thanks, it looks interesting. After seeing the examples, it looks
(from the point of view of a non-math person) like there is no big
advantage to such syntax, as the simplest way has code that is
easiest to understand.

Shoehorning lambda calculus into Lua, I guess, can be done in
many, many different ways. A long-winded syntax is a net loss to
the programmer, I think, as the programmer has a bigger cognitive
load to handle in order to grok the code. A math-like syntax on
the other hand, will look more like a formula, but will have a
distinctly different syntax or smell to it.

I'm not sure I follow that it'd have to be "shoehorned." Doesn't Lua contain, or isn't it just a superset of the lambda calculus? Lua is of course a lot more procedural than most languages implementing lambda calculus, but...

From Wikipedia: ( http://en.wikipedia.org/wiki/Lambda_calculus )

Formally, a lambda _expression_ is defined inductively as one of the following:

1. V, a variable, where V is any identifier. (The precise set of identifiers is arbitrary, but must be infinite.)
2. (λ V. E), an abstraction, where V is any identifier and E is any lambda _expression_. An abstraction corresponds to an anonymous function.
3. E E′, an application, where E and E′ are any lambda expressions. An application corresponds to calling a function (E) with an argument (E′ ).
Lua provides facilities for all three of those expressions, the critical one being abstractions / anonymous functions.

• Follow-Ups: