[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: special forms, take two (was Re: A lua version of "amb")
- From: Jay Carlson <nop@...>
- Date: Wed, 29 Feb 2012 17:56:01 +0000
On Wed, Feb 29, 2012 at 5:37 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>>> This is one of those cases where function declaration syntax inside a
>>>> table would work for some kinds of use too:
>>>>
>>>> switch(c, {
>>>> function p() print(a) end;
>>>> function q() os.exit() end;
>>>> function e() eval(args) end;
>>>> })
>>>>
>>>> but that's dependent on the cases being suitable as table keys.
>>>
>>> I.e. the cases must not be nil of NaN?
>>
>> How did the nil make it past my assert?
>>
>
> OK, my point was put too cryptically. Let's try again.
>
> You said: "dependent on the cases being suitable as table keys".
> But _all_ Lua values, except nil and NaN, are valid table keys.
> For example,
>
> tbl = { [function(a) print(a) end] = 'just print it' }
>
> is valid, and `next(tbl)"hello"` prints "hello".
>
> So, I don't understand what you mean by "dependent on the cases being
> suitable as table keys".
Oh. I just meant that the {function a() end} -> {a=function() end}
thing (which has come up a couple times) only gets you something in
the switch/case situation if all of the cases you care about are valid
Lua identifiers.
This is probably more true in state machines and callback tables,
where the control driver, like say lxp, will use callbacks like
"beginElement" rather than 0 or io.stdout.
Jay
- References:
- A lua version of "amb", Xavier Wang
- special forms, take two (was Re: A lua version of "amb"), Jay Carlson
- Re: special forms, take two (was Re: A lua version of "amb"), Fabien
- Re: special forms, take two (was Re: A lua version of "amb"), Jay Carlson
- Re: special forms, take two (was Re: A lua version of "amb"), Dirk Laurie
- Re: special forms, take two (was Re: A lua version of "amb"), Jay Carlson
- Re: special forms, take two (was Re: A lua version of "amb"), Dirk Laurie