digitalmars.D - syntax idea: simplifed ifs
- dennis luehring (9/9) Apr 10 2006 for example how often do we use constructs like
- Derek Parnell (7/15) Apr 10 2006 A good one too, in my opinion. The || symbol would also be useful.
- dennis luehring (3/24) Apr 10 2006 or think of
- Derek Parnell (13/38) Apr 10 2006 Not sure what that would mean ... is it ...
- Ameer Armaly (16/25) Apr 10 2006 Considering that you can't have multiple assignments to a variable, if y...
- Derek Parnell (18/50) Apr 10 2006 The problem with 'switch' is it requires literals or consts. One can't d...
- Ameer Armaly (4/55) Apr 10 2006 That's true. In such a case I think that the above proposal might work,...
- Hasan Aljudy (13/28) Apr 10 2006 I've always wanted something like this!!!! but I think the proposed
- Derek Parnell (9/45) Apr 10 2006 Try not using literals ... ;-)
- Bruno Medeiros (11/51) Apr 13 2006 In the template example? Why did both of you think a template was
- BCS (4/33) Apr 13 2006 templates insure inlining and provide more options for optimization. not...
- Derek Parnell (10/16) Apr 13 2006 You are missing nothing ... we can do lots of stuff using functions.
- Bruno Medeiros (6/29) Apr 14 2006 I wasn't saying we should use functions, I was just saying they were
- Hasan Aljudy (6/61) Apr 13 2006 Sure you can do them with functions, it just adds a bit of unnecessary
- Dan (9/9) Apr 14 2006 In ECMAScript itself, you can write code like:
- Alexander Panek (19/34) Apr 15 2006 [code]
- Dan (10/23) Apr 21 2006 Dear Alexander, I'm not sure if you've read the manual on what differen...
- dennis luehring (11/28) Apr 11 2006 oh no! what we need is more syntactic sugar - not another boost library
- Fredrik Olsson (11/15) Apr 18 2006 This problem domain and and then some is easily solved with sets, as I
- dennis luehring (5/24) Apr 18 2006 how would you write these example in your in syntax?
- Fredrik Olsson (12/39) Apr 19 2006 Not that easy as sets is mostly not a simple solution for complex
- dennis luehring (4/19) Apr 19 2006 thats clear - but you can't write my above examples simpler with your "i...
- BCS (5/14) Apr 19 2006 I wouldn't use any shorthand, I would use the expanded form
- Chris Miller (7/16) Apr 11 2006 The suggestions parse as arrays, which is unfriendly to context-free
- Derek Parnell (15/40) Apr 11 2006 I wouldn't get too hung up be the specific syntax quite yet ;-) But is t...
- BCS (18/23) Apr 11 2006 Why not let it?
- pragma (8/33) Apr 11 2006 This makes a lot of sense. So what we really need is ad-hoc array decla...
- Charles (3/18) Apr 11 2006 I've often wanted this, gets my vote, if you cound find a syntax that
- Deewiant (11/30) Apr 11 2006 How about just curly brackets? For instance:
- James Dunne (7/44) Apr 11 2006 Not context-free.
- David Medlock (12/27) Apr 12 2006 Its a little off topic, but every expression in the
- Bruno Medeiros (14/29) Apr 13 2006 Dear Gods, no! I'm against adding such a specific rule to the language,
- Frank Benoit (1/1) Apr 13 2006 full ack
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
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
Derek Parnell wrote:On Tue, 11 Apr 2006 08:04:21 +1000, dennis luehring <dl.soluz gmx.net> wrote:or think of if( [a || b || c ] >= [ h && b ] )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 )
Apr 10 2006
On Tue, 11 Apr 2006 00:24:14 +0200, dennis luehring wrote:Derek Parnell wrote: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 AMOn Tue, 11 Apr 2006 08:04:21 +1000, dennis luehring <dl.soluz gmx.net> wrote:or think of if( [a || b || c ] >= [ h && b ] )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 )
Apr 10 2006
"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 dennisConsidering that you can't have multiple assignments to a variable, if 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.
Apr 10 2006
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...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 AMfor 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 dennisConsidering that you can't have multiple assignments to a variable, if 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.
Apr 10 2006
"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:That's true. In such a case I think that the above proposal might work, or perhaps the templates that Hasan suggested."dennis luehring" <dl.soluz gmx.net> wrote in message news:e1ekp6$jr7$1 digitaldaemon.com...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; }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 dennisConsidering that you can't have multiple assignments to a variable, if 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.-- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 10:01:40 AM
Apr 10 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 dennisI'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
On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote:dennis luehring wrote: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 AMfor 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 dennisI'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
Derek Parnell wrote:On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote: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#Ddennis luehring wrote:Try not using literals ... ;-)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 dennisI'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 13 2006
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] )templates insure inlining and provide more options for optimization. not terribly critical but...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? :ohmm, 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 ) )
Apr 13 2006
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? :oYou 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
Derek Parnell wrote:On Fri, 14 Apr 2006 05:58:54 +1000, Bruno Medeiros <brunodomedeirosATgmail SPAM.com> wrote: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#DOne 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? :oYou 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 14 2006
Bruno Medeiros wrote:Derek Parnell wrote: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.On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote: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? :odennis luehring wrote:Try not using literals ... ;-)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 dennisI'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 13 2006
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
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
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?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.
Apr 21 2006
I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.another ideahmm, 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
Hasan Aljudy skrev:dennis luehring wrote:<SNIP>I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.This problem domain and and then some is easily solved with sets, as I 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
Fredrik Olsson schrieb:Hasan Aljudy skrev: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 dennisdennis luehring wrote:<SNIP>I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.This problem domain and and then some is easily solved with sets, as I 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
dennis luehring skrev:Fredrik Olsson schrieb:Not that easy as sets is mostly not a simple solution for complex conditions, but a simple solution to complex set problems.Hasan Aljudy skrev:how would you write these example in your in syntax?dennis luehring wrote:<SNIP>I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.This problem domain and and then some is easily solved with sets, as I 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 Olssonif( 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: 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
Fredrik Olsson schrieb:how would you write these example in your in syntax?Not that easy as sets is mostly not a simple solution for complex 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" operationsif (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
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 dennisI wouldn't use any shorthand, I would use the expanded form if( x == a && x == !b || x == c ) if( x == a && ( x == !b || x == c ) ) to much shorthand just leads to confusion
Apr 19 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 dennisThe 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
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: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 PMfor 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 dennisThe 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
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
In article <e1glh1$2fhf$1 digitaldaemon.com>, BCS says...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 yahooThe 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
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 dennisI've often wanted this, gets my vote, if you cound find a syntax that keeps it context free.
Apr 11 2006
Charles wrote:dennis luehring wrote: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".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 dennisI've often wanted this, gets my vote, if you cound find a syntax that keeps it context free.
Apr 11 2006
Deewiant wrote:Charles wrote:Not context-free. '{' begins a statement. Having '{' also begin an expression would cause problems due to expression-statements. -- Regards, James Dunnedennis luehring wrote: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".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 dennisI've often wanted this, gets my vote, if you cound find a syntax that keeps it context free.
Apr 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 dennisIts 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
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 dennisDear 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