|
|
|
That could indeed be a solution.
I understand that allowing the form I mentioned would require a change in the grammar. However I think that this would not require much changes. I am not familiar with the Groovy parser and the AST that it generates, but a naive solution would be to transform an AST such as: r_conditional("unless")
/ \
b=true_branch c=condition
to: if (not c)
/
b
representing this in the AST is not the primary issue here. There are several idioms in Groovy and most of our grammar is based on different forms of method calls. For example
if (b) {println foo}
doSomething() unless (x > 10) {doSomething()}
I'd rather do {...}.unless(condition) – putting conditional methods onto closures would be pretty nifty, and keep with the Groovy feel.
Julien, I would suggest you raise the issue on the groovy-user list to see the reactions of others.
Done. Let's see what people think about the idea
+1000 for unless, except I think we should stick with pre statement rather post statement. To be clear...
unless (x > 10) doSomething() if (x < 10) triggerSomethingNasty() I actually prefer the ruby/perl style of having the condition afterwards for single statement expressions, but since Groovy already supports having the condition before the statement I would advocate sticking with this. I think having conditions as right-hand side properties of an expression is awful – especially in a read left-to-right language. Just because Perl and Ruby do it doesn't make it good and desirable – Python doesn't have the structure as was originally stated.
My mistake, Python indeed doesn't have those constructs.
No problem, I just wanted to ensure no mistakes got turned into facts
It seems the debate is lively and alive on the mailing list, so I guess the best bet is to wait for things to iterate to a conclusion there and then post a summary item here. |
||||||||||||||||||||||||||||||||||||||||||
unless(x>10){doSomething}{doSomething}.unless(x>10)