www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - syntax idea: simplifed ifs

reply dennis luehring <dl.soluz gmx.net> writes:
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
Apr 10 2006
next sibling parent reply "Derek Parnell" <derek psych.ward> writes:
On Tue, 11 Apr 2006 08:04:21 +1000, 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)

A good one too, in my opinion. The || symbol would also be useful. if ( [a || b || c] >= h ) -- Derek Parnell Melbourne, Australia
Apr 10 2006
parent reply dennis luehring <dl.soluz gmx.net> writes:
Derek Parnell wrote:
 On Tue, 11 Apr 2006 08:04:21 +1000, 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)

A good one too, in my opinion. The || symbol would also be useful. if ( [a || b || c] >= h )

or think of if( [a || b || c ] >= [ h && b ] )
Apr 10 2006
parent Derek Parnell <derek psych.ward> writes:
On Tue, 11 Apr 2006 00:24:14 +0200, dennis luehring wrote:

 Derek Parnell wrote:
 On Tue, 11 Apr 2006 08:04:21 +1000, 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)

A good one too, in my opinion. The || symbol would also be useful. if ( [a || b || c] >= h )

or think of if( [a || b || c ] >= [ h && b ] )

Not sure what that would mean ... is it ... if ( (a >= h || b >= h || c => h) && ((a >= b || b >= b || c => b))) OR if ( (a >= h && a >= b) || (b => h && b >= b) || (c => h && c >= b) ) I think the idea should be kept at one '[...]' group only and one of '&&','||' per group ( that is ... don't mix && and || inside the [] ). -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 9:57:47 AM
Apr 10 2006
prev sibling next sibling parent reply "Ameer Armaly" <ameer_armaly hotmail.com> writes:
"dennis luehring" <dl.soluz gmx.net> wrote in message 
news:e1ekp6$jr7$1 digitaldaemon.com...
 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

had that many possible OR conditions,, couldn't you just use a combined switch like so: switch(x) { case 10: case 20: case 30: ... default: break; } This still leaves open the issue of multiple variables though; what you suggest may work.
Apr 10 2006
parent reply Derek Parnell <derek psych.ward> writes:
On Mon, 10 Apr 2006 19:18:55 -0400, Ameer Armaly wrote:

 "dennis luehring" <dl.soluz gmx.net> wrote in message 
 news:e1ekp6$jr7$1 digitaldaemon.com...
 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

had that many possible OR conditions,, couldn't you just use a combined switch like so: switch(x) { case 10: case 20: case 30: ... default: break; } This still leaves open the issue of multiple variables though; what you suggest may work.

The problem with 'switch' is it requires literals or consts. One can't do ... switch (h) { case a: case b: case c: ... break; default: break; } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 10:01:40 AM
Apr 10 2006
parent "Ameer Armaly" <ameer_armaly hotmail.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message 
news:noyfbcyf3t01$.m2gl86mb13se.dlg 40tude.net...
 On Mon, 10 Apr 2006 19:18:55 -0400, Ameer Armaly wrote:

 "dennis luehring" <dl.soluz gmx.net> wrote in message
 news:e1ekp6$jr7$1 digitaldaemon.com...
 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

you had that many possible OR conditions,, couldn't you just use a combined switch like so: switch(x) { case 10: case 20: case 30: ... default: break; } This still leaves open the issue of multiple variables though; what you suggest may work.

The problem with 'switch' is it requires literals or consts. One can't do ... switch (h) { case a: case b: case c: ... break; default: break; }

perhaps the templates that Hasan suggested.
 -- 
 Derek
 (skype: derek.j.parnell)
 Melbourne, Australia
 "Down with mediocracy!"
 11/04/2006 10:01:40 AM 

Apr 10 2006
prev sibling next sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
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 ;)
Apr 10 2006
next sibling parent reply Derek Parnell <derek psych.ward> writes:
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 ... ;-) The expression( x == a && x == b && x == c ) is not always false. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 10:15:53 AM
Apr 10 2006
parent reply Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
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

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 ... ;-)

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
Apr 13 2006
next sibling parent BCS <BCS_member pathlink.com> writes:
Bruno Medeiros wrote:
 Derek Parnell wrote:
 On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote:
 dennis luehring wrote:

 if( x ==  10 && x == 20 && x == 30 )
 simplified:
 if( x == [10 && 20 && 30] )




 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 ) )


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

templates insure inlining and provide more options for optimization. not terribly critical but...
Apr 13 2006
prev sibling next sibling parent reply "Derek Parnell" <derek psych.ward> writes:
On Fri, 14 Apr 2006 05:58:54 +1000, Bruno Medeiros  
<brunodomedeirosATgmail SPAM.com> wrote:

 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

You are missing nothing ... we can do lots of stuff using functions. equals(result, add(x,y)) or result = x + y; Why do we have such syntax sugar? -- Derek Parnell Melbourne, Australia
Apr 13 2006
parent Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
Derek Parnell wrote:
 On Fri, 14 Apr 2006 05:58:54 +1000, Bruno Medeiros 
 <brunodomedeirosATgmail SPAM.com> wrote:
 
 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

You are missing nothing ... we can do lots of stuff using functions. equals(result, add(x,y)) or result = x + y; Why do we have such syntax sugar? --Derek Parnell Melbourne, Australia

I wasn't saying we should use functions, I was just saying they were more adequate here than a template. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Apr 14 2006
prev sibling parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Bruno Medeiros wrote:
 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 ... ;-)

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

Sure you can do them with functions, it just adds a bit of unnecessary overhead. I don't usually care much if a nice structure/design adds a small runtime overhead, but I noticed that alot of D'ers do care, so that's why I pospsed a templated solution.
Apr 13 2006
parent reply Dan <Dan_member pathlink.com> writes:
In ECMAScript itself, you can write code like:

a && a.doSomething();
or
a = a || defaultValue;

It feels so much better than:

if(a) a.doSomething();
if(!a) a = defaultValue;

Maybe because it doesn't need indentation.  Maybe because it falsely makes me
feel better about branching.  Maybe it's 'cause logicals are just sexy.
Apr 14 2006
parent reply Alexander Panek <alexander.panek brainsware.org> writes:
Dan wrote:
 In ECMAScript itself, you can write code like:
 
 a && a.doSomething();
 or
 a = a || defaultValue;
 
 It feels so much better than:
 
 if(a) a.doSomething();
 if(!a) a = defaultValue;
 
 Maybe because it doesn't need indentation.  Maybe because it falsely makes me
 feel better about branching.  Maybe it's 'cause logicals are just sexy.
 
 

[code] import std.stdio; int main ( char [][] args ) { uint a = 10; uint b = 0; b |= a; writefln(b); a |= b; writefln(a); return 0; } [/code] Output: :!./test 10 10 Works quite fine for me.
Apr 15 2006
parent Dan <Dan_member pathlink.com> writes:
 a && a.doSomething();
 or
 a = a || defaultValue;
 
 It feels so much better than:
 
 if(a) a.doSomething();
 if(!a) a = defaultValue;

b |= a; writefln(b); a |= b; writefln(a); Works quite fine for me.

Dear Alexander, I'm not sure if you've read the manual on what different operators do exactly. || is a logical or, that is, it returns one OR the other. | is a bitwise or, that is, it returns a value in which if a given bit is set in the value on either side, it will be set in the return value. |= is a bitwise or, so if you say: x = 1; x |= 2; // 3 x = 1 || 2; // 1 x = 0 || 2; // 2 You with me?
Apr 21 2006
prev sibling next sibling parent dennis luehring <dl.soluz gmx.net> writes:
 I've always wanted something like this!!!! but I think the proposed 
 syntax might not fit very well with the D grammar.

another idea
 hmm, come to think of it, maybe it can already be implemented with 
 templates.

oh no! what we need is more syntactic sugar - not another boost library (hell) :-)
 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 ;)

example version 2: if( x == a && x == b && x == c ) => if( x == [a && b && c] ) --> or maybe even "if( x == [a,b,c](&&))" but this goes a little bit to fast into the "how can we integrate vector stuff" direction... ciao dennis
Apr 11 2006
prev sibling parent reply Fredrik Olsson <peylow treyst.se> writes:
Hasan Aljudy skrev:
 dennis luehring wrote:

 I've always wanted something like this!!!! but I think the proposed 
 syntax might not fit very well with the D grammar.
 

have proposed at many occasions in the past :). As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well. The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing. Only some more fancy C/D like syntax is needed. // Fredrik Olsson
Apr 18 2006
parent reply dennis luehring <dl.soluz gmx.net> writes:
Fredrik Olsson schrieb:
 Hasan Aljudy skrev:
 dennis luehring wrote:

 I've always wanted something like this!!!! but I think the proposed 
 syntax might not fit very well with the D grammar.

have proposed at many occasions in the past :). As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well. The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing. Only some more fancy C/D like syntax is needed. // Fredrik Olsson

how would you write these example in your in syntax? if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c ) if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) ) ciao dennis
Apr 18 2006
next sibling parent reply Fredrik Olsson <peylow treyst.se> writes:
dennis luehring skrev:
 Fredrik Olsson schrieb:
 Hasan Aljudy skrev:
 dennis luehring wrote:

 I've always wanted something like this!!!! but I think the proposed 
 syntax might not fit very well with the D grammar.

have proposed at many occasions in the past :). As arrays are supersets of sets (Array is an ordered set), my proposals works nicely with the array suggestions in this thread as well. The proposal is to steal the functionality as is from Pascal, no need to invent something new, when others already have done it, and put it to three decades of testing. Only some more fancy C/D like syntax is needed. // Fredrik Olsson

how would you write these example in your in syntax?

conditions, but a simple solution to complex set problems.
 if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c )
 
 if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) )
 

better example: if (x == [a || b || c]) --> if (x == a || x == b || x == c) would be if (x in <a, b, c>) But the true power lies in what can be done with sets, unions, intersections, etc. regards // Fredrik Olsson
Apr 19 2006
parent dennis luehring <dl.soluz gmx.net> writes:
Fredrik Olsson schrieb:
 how would you write these example in your in syntax?

conditions, but a simple solution to complex set problems.
 if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c )

 if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) )


 These are not good examples of where sets strength lies, this is a 
 better example:

set strength lies in "or" operations
 if (x == [a || b || c]) --> if (x == a || x == b || x == c)
 would be
 if (x in <a, b, c>)

thats clear - but you can't write my above examples simpler with your "in"
 But the true power lies in what can be done with sets, unions, 
 intersections, etc.

examples - "in" isn't enough (its just the "or" part of my idea)
Apr 19 2006
prev sibling parent BCS <BCS_member pathlink.com> writes:
dennis luehring wrote:
 
 how would you write these example in your in syntax?
 
 if( x == [ a && !b || c ] ) --> if( x == a && x == !b || x == c )
 
 if( x == [ a && (!b || c)] ) --> if( x == a && ( x == !b || x == c ) )
 
 ciao dennis
 

if( x == a && x == !b || x == c ) if( x == a && ( x == !b || x == c ) ) to much shorthand just leads to confusion
Apr 19 2006
prev sibling next sibling parent reply "Chris Miller" <chris dprogramming.com> writes:
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);
Apr 11 2006
next sibling parent Derek Parnell <derek psych.ward> writes:
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
Apr 11 2006
prev sibling parent reply BCS <BCS_member pathlink.com> writes:
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)){...}
Apr 11 2006
parent pragma <pragma_member pathlink.com> writes:
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
Apr 11 2006
prev sibling next sibling parent reply Charles <noone nowhere.com> writes:
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.
Apr 11 2006
parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
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".
Apr 11 2006
parent James Dunne <james.jdunne gmail.com> writes:
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
Apr 11 2006
prev sibling next sibling parent David Medlock <noone nowhere.com> writes:
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
Apr 12 2006
prev sibling parent reply Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
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
Apr 13 2006
parent Frank Benoit <keinfarbton nospam.xyz> writes:
full ack
Apr 13 2006