lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Dec 29, 2010 at 09:22:36AM +0200, Dirk Laurie wrote:
> 
> Because of the need for a local name for the function, you can't define
> an anonymous recursive function, e.g. for use in an argument list.  
> 
The post containing this was followed by a sequence of posts with an 
unusually high noise-to-signal ratio, mainly focussing on how the
poster would have written the code of my illustrative examples, usually
without actually testing his suggestion, and totally ignoring the above 
sentence.

So let me rephrase the point in short sentences.

1. The construction "function(x) ... end" defines an anonymous function.
2. "function foo(x)" instead of "foo=function(x)" is mere syntactic sugar.
   You are actually doing the same thing.
3. Anonymous functions are not only assigned.  They can also appear in
    argument lists and arrays.  So we really use them.
4. There appears to be no way to define an anonymous recursive function.
5. Therefore recursive functions in argument lists and tables must
    be named functions.
6. Unless one can find a way to mimic them by some sort of anonymous
    recursive function constructor.
7. Which I think a sufficiently clever programmer could write, probably
    by using pattern matching and loadin.
8. And which clever programmer I vainly hoped was listening in.

Dirk