On 12/07/2011 07:02 PM, Nick Sabalausky wrote:
"Adam Ruppe"<destructiona...@gmail.com> wrote in message
news:jbo8rr$rhh$1...@digitalmars.com...
Alex Rønne Petersen Wrote:
I really do not see the value in allowing such syntax in the first
place. I've been told that one argument was that generated code might
use it, but I have no idea why it would be needed.
Aside from the compiler's implementation, one possible use
is something I ended up doing in Javascript recently.
I have a thing that takes an attribute and pastes it into a code
string to check it.
given validate="this.value.length> 3"
it writes:
if(!(this.value.length> 3))
return false; // failed validation
since the given string is inside an if statement, you can't put
a semicolon in there.
So, if you have a check more complex than returning a boolean
and want to stuff it all in that string (so functions are out), the
comma lets you do it:
validate="do something, true"
This is pretty ugly style that I think I've only ever done in D inside
a for loop... but the point is sometimes something comes up, and
it's nice to have another option available, even if it is ugly.
Don't know about JS, but D can solve the same problem with anon delegates,
which is less obscure anyway.
I think Don said that DMD cannot currently inline any delegates. Imho
the spec should even *require* inlining in the special case that such a
delegate is immediately executed. (even for debug builds).