syntax idea: simplifed ifs

pragma pragma_member at pathlink.com
Tue Apr 11 10:05:24 PDT 2006


In article <e1glh1$2fhf$1 at digitaldaemon.com>, BCS says...
>
>>
>>The suggestions parse as arrays, which is unfriendly to context-free  
>>grammar...
>>
>>static int[] foo = [1 && 2 && 3];
>>static int[] bar = [ 1, 2, 3 ];
>>writefln(foo, bar);
>
>
>Why not let it?
>
>Compound_expr :: Expr Rel_op ArrayExpr
>Compound_expr :: ArrayExpr Rel_op Expr
>
>
>If you always assume "or" you can still make things work.
>
>
>int[] a = [1, 2, 3];
>int b;
>
>// b is equal to one or more of a
>if(a == b){...}   
>// b is not equal to any of a
>if(!(a == b)){...}   
>
>// b is less than at least one of a
>if(a > b){...}
>// b is less than all of a
>if(!(a < b)){...}
>
>// b is more than at least one of a
>if(a < b){...}
>// b is more than all of a
>if(!(a > b)){...}
>

This makes a lot of sense.  So what we really need is ad-hoc array declarations,
akin to the array initalization gripe on the feature request list?  How would
that fold into the shorthand syntax that spawned this thread?

Example:  if(foo < [1,2,3,4,5]){}

would that require a cast, or can it even be allowed?

if(foo < cast(uint[])[1,2,3,4,5]){}

- EricAnderton at yahoo



More information about the Digitalmars-d mailing list