lua-users home
lua-l archive

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


On Nov 9, 2007 10:41 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
My vote is for David Given's suggestion:

match k
 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
end

It's understood to involve just linear chains of elseifs ;)

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.