Vincent Pit wrote:
>For some time, I've tried to implement rvalue given blocks. The problem
>I met was that allowing given blocks to be expressions led to conflicts
>in the grammar
...
>On Matt's advice, I've extracted all the non-syntaxical part of my
>implementation.
+1 on the value-yielding semantics being separate from
statement-as-expression syntax. The semantic change brings "given" in
line with "if" et al, and seems entirely appropriate to include in 5.12,
as rectifying an earlier oversight. It doesn't feel like a new feature.
Statement-as-expression is a wider issue. Whatever is done for "given"
as an expresssion should be done for "if" and other compound statement
types too. Any new syntax here is, of course, an entirely new feature.
I think we should strictly avoid any syntax that leads to ambiguity of
the type Vincent has noted. Probably the cleanest way is to introduce
a new kind of bracketing punctuation:
NEW SYNTAX EQUIVALENT TO
given[($foo) { do { given($foo) {
when(3) { ... } when(3) { ... }
}] } }
if[($a < $b) { do { if($a < $b) {
... ...
}] } }
while[($a < $b) { do { while($a < $b) {
... ...
}] } }
# using TryCatch
try[{ do { try {
... ...
} catch($e) { } catch($e) {
... ...
}] } }
The TryCatch module could just about implement this type of syntax now,
as a prototype. Could certainly do it if reimplemented using the keyword
plugin mechanism. Furthermore, this syntax could be prototyped for "if"
et al by an XS module using the keyword plugin mechanism, modulo some
difficulty in parsing the controlling expression.
-zefram
Thread Previous
|
Thread Next