[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Switch/Case statements revisited
- From: Fabien <fleutot+lua@...>
- Date: Fri, 9 Nov 2007 12:02:24 +0100
On Nov 9, 2007 10:41 AM, steve donovan <email@example.com> wrote:
My vote is for David Given's suggestion:
It's understood to involve just linear chains of elseifs ;)
with 10, 11 then return 1 end
with 12 then return 2 end
with i if 13<=i and i<=16 then return 4 end
Since it was a proposal to tune the syntax of metalua's pattern matching, it's actually compiled into gotos, which don't all nest nicely enough to be encoded as elseifs (the compilation of a pattern is not always trivial). Notice those gotos don't require patching, they're implemented with regular VM instructions. The only point with them is, I've never checked how they play along with LuaJIT yet.
As for the syntax proposal, I'm slightly put off by the final double end.
And finally, just to anticipate a Dijkstra quote: gotos might be harmful when written in hand-written code, but they're very valuable for compilers, including non-trivial macro systems. They've got no default syntax in metalua, although nothing prevents users from adding one.