[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Switch/Case statements revisited
- From: Norman Ramsey <nr@...>
- Date: Mon, 12 Nov 2007 20:26:45 -0500
> Norman Ramsey <nr@eecs.harvard.edu> writes:
> > Since Lua's syntax was inspired by Pascal
>
> To me, Lua's syntax looks more like it was inspired by CLU (a very nice
> language, btw)...
Interesting. I'm a big fan. Certainly the semicolons-are-optional
statement terminator is straight out of CLU.
CLU's case statement is the elimination construct for the built-in
variant record clusters. It is roughly
tagcase <expression>
tag <name>, ... : statements
...
others : statements
end
Not so well suited to Lua since one would want a case statement to
apply to any Lua value. But as usual they've done a good job of
eliminating syntactically noisy curly braces and vertical bars (at the
cost of syntactically noisy keywords.
The same structure might be pleasant enough with more Lua-like keywords.
Here's a proposal extending the 5.1 reference grammar on page 95.
Bold is keywords, curlies are zero-or-more, brackets are zero-or-one:
*case* exp
{ *is* explist1 : block }
[ *otherwise* : block ]
*end*
Norman