lua-users home
lua-l archive

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


I've been wondering the same thing, especially as "function foo()" is
just syntactic sugar for "foo = function()". But I'm guessing it has
something to do with how the parser is built.

I do think it would be nice to allow it. Given the fact that keywords
(such as "function") are not allowed as names (i.e. string keys using
the "table.key" or "table:key" syntax), I think it shouldn't be much
of a problem for the parser.


On 21/02/2008, steve donovan <steve.j.donovan@gmail.com> wrote:
> A good question. Arguably the second form would be very useful for
>  class definitions. But table constructors currently only take values,
>  like the anonymous function in the first example.
>
>  steve d.
>
>
>  On Thu, Feb 21, 2008 at 3:30 AM, Tim Hunter <TimHunter@nc.rr.com> wrote:
>  > Why does this work:
>  >
>  >  t = {
>  >     f = function()
>  >             print("hello")
>  >         end
>  >  }
>  >
>  >  But this doesn't?
>  >
>  >  t = {
>  >     function f()
>  >         print("hello")
>  >     end
>  >  }
>  >
>  >
>  >
>