April 11, 2006
On Mon, 10 Apr 2006 18:04:21 -0400, dennis luehring <dl.soluz@gmx.net> wrote:

> for example how often do we use constructs like
>
> if( x ==  10 && x == 20 && x == 30 )
>
> simplified:
> if( x == [10 && 20 && 30] )
>
> if( a >= h && b >= h && c >= h )
>
> simplified:
> if( [a && b && c] >= h )
>
> (just an idea)
>
> ciao dennis

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);
April 11, 2006
On Tue, 11 Apr 2006 04:14:49 -0400, Chris Miller wrote:

> On Mon, 10 Apr 2006 18:04:21 -0400, dennis luehring <dl.soluz@gmx.net> wrote:
> 
>> for example how often do we use constructs like
>>
>> if( x ==  10 && x == 20 && x == 30 )
>>
>> simplified:
>> if( x == [10 && 20 && 30] )
>>
>> if( a >= h && b >= h && c >= h )
>>
>> simplified:
>> if( [a && b && c] >= h )
>>
>> (just an idea)
>>
>> ciao dennis
> 
> 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);

I wouldn't get too hung up be the specific syntax quite yet ;-) But is the concept a good idea????

  Compound_expr :: Expr Rel_op Expr_set
  Compound_expr :: Expr_set Rel_op Expr
  Expr_set      :: Es_prefix Es_list Es_suffix
  Es_list       :: Expr Es_bool_expr ...
  Es_bool_expr  :: Bool_op Expr

Now all we have to do is define what the prefix and suffix is.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
11/04/2006 6:35:57 PM
April 11, 2006
>
>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)){...}

April 11, 2006
dennis luehring wrote:
> for example how often do we use constructs like
> 
> if( x ==  10 && x == 20 && x == 30 )
> 
> simplified:
> if( x == [10 && 20 && 30] )
> 
> if( a >= h && b >= h && c >= h )
> 
> simplified:
> if( [a && b && c] >= h )
> 
> (just an idea)
> 
> ciao dennis

I've often wanted this, gets my vote, if you cound find a syntax that keeps it context free.
April 11, 2006
In article <e1glh1$2fhf$1@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
April 11, 2006
Charles wrote:
> dennis luehring wrote:
>> for example how often do we use constructs like
>>
>> if( x ==  10 && x == 20 && x == 30 )
>>
>> simplified:
>> if( x == [10 && 20 && 30] )
>>
>> if( a >= h && b >= h && c >= h )
>>
>> simplified:
>> if( [a && b && c] >= h )
>>
>> (just an idea)
>>
>> ciao dennis
> 
> I've often wanted this, gets my vote, if you cound find a syntax that keeps it context free.

How about just curly brackets? For instance:

if (x == {10 && 20 && 30})

There's no way "10 && 20 && 30" could be allowed by itself surrounded by curly brackets anywhere else; in a function definition or the like it would need at least a semicolon following, and since a while ago effectless expressions were banned it wouldn't be allowed even then.

Although I must say I prefer BCS's suggestion, earlier. I think it also obviates some people's wishes that "x in array" should work for non-associative arrays, meaning "array contains x". According to BCS's ideas one could simply use "x == array".
April 12, 2006
Deewiant wrote:
> Charles wrote:
> 
>>dennis luehring wrote:
>>
>>>for example how often do we use constructs like
>>>
>>>if( x ==  10 && x == 20 && x == 30 )
>>>
>>>simplified:
>>>if( x == [10 && 20 && 30] )
>>>
>>>if( a >= h && b >= h && c >= h )
>>>
>>>simplified:
>>>if( [a && b && c] >= h )
>>>
>>>(just an idea)
>>>
>>>ciao dennis
>>
>>I've often wanted this, gets my vote, if you cound find a syntax that
>>keeps it context free.
> 
> 
> How about just curly brackets? For instance:
> 
> if (x == {10 && 20 && 30})
> 
> There's no way "10 && 20 && 30" could be allowed by itself surrounded by curly
> brackets anywhere else; in a function definition or the like it would need at
> least a semicolon following, and since a while ago effectless expressions were
> banned it wouldn't be allowed even then.
> 
> Although I must say I prefer BCS's suggestion, earlier. I think it also obviates
> some people's wishes that "x in array" should work for non-associative arrays,
> meaning "array contains x". According to BCS's ideas one could simply use "x ==
> array".

Not context-free.

'{' begins a statement.  Having '{' also begin an expression would cause problems due to expression-statements.

-- 
Regards,
James Dunne
April 12, 2006
dennis luehring wrote:

> for example how often do we use constructs like
> 
> if( x ==  10 && x == 20 && x == 30 )
> 
> simplified:
> if( x == [10 && 20 && 30] )
> 
> if( a >= h && b >= h && c >= h )
> 
> simplified:
> if( [a && b && c] >= h )
> 
> (just an idea)
> 
> ciao dennis

Its a little off topic, but every expression in the
Icon language(http://www.cs.arizona.edu/icon/) generates one or more values, so the | operator works like you expect:

if ( a > (b | d) <= 10 ) { .. }

this expession is equivalent to

a > (b | d) means that the expression will return
b if a > b, or it will return d if ( a > d ) or it will return nothing, in which case the whole statement fails.

the result is then passed to  '<= 10' which can also fail or produce 10.

This is called goal driven evaluation, and makes for succinct programs.

-DavidM


April 13, 2006
dennis luehring wrote:
> for example how often do we use constructs like
> 
> if( x ==  10 && x == 20 && x == 30 )
> 
> simplified:
> if( x == [10 && 20 && 30] )
> 
> if( a >= h && b >= h && c >= h )
> 
> simplified:
> if( [a && b && c] >= h )
> 
> (just an idea)
> 
> ciao dennis

Dear Gods, no! I'm against adding such a specific rule to the language, thus increasing it's complexity, just for IMO a *very small* gain in term of syntactic sugar (and change agility).

Like someone said already, if we had array literals we could probably have a general solution, like:
  [10, 20, 30].contains(x)
or:
  x in [10, 20, 30]

But even if we can't find a better alternative such as this one, I'm still against this specific idea.


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
April 13, 2006
Derek Parnell wrote:
> On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote:
> 
>> dennis luehring wrote:
>>> for example how often do we use constructs like
>>>
>>> if( x ==  10 && x == 20 && x == 30 )
>>>
>>> simplified:
>>> if( x == [10 && 20 && 30] )
>>>
>>> if( a >= h && b >= h && c >= h )
>>>
>>> simplified:
>>> if( [a && b && c] >= h )
>>>
>>> (just an idea)
>>>
>>> ciao dennis
>> I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
>>
>> hmm, come to think of it, maybe it can already be implemented with templates.
>>
>> so,
>>
>> if( x == 10 || x == 20 || x == 30 )
>>
>> becomes:
>> if( equals!(x).anyOf( 10, 20, 30 ) )
>>
>> or something like that!
>>
>> any template guru up to it?
>>
>> On a side note: the expression( x == 10 && x == 20 && x == 30 ) is rediclious, it's always false ;)
> 
> Try not using literals ... ;-)
> 
In the template example? Why did both of you think a template was necessary? One can do this with plain old functions. Well, with typesafe variadic functions that is:
  equalsAny( x + y, 10, b, c)
also possible (but somewhat weird..) :
  equals(x + y).AnyOf(10, b, c)

Or am I missing something terribly obvious? :o


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D