syntax idea: simplifed ifs
David Medlock
noone at nowhere.com
Wed Apr 12 05:40:47 PDT 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
More information about the Digitalmars-d
mailing list