if-expressions
Charles D Hixson
charleshixsn at earthlink.net
Sat Oct 27 07:17:38 PDT 2007
Bent Rasmussen wrote:
> I've been away from D for quite a while, but am anxious to get back and
> use the new features.
>
> Reading the newsgroup to catch up a little, I remembered a feature of
> another language (haXe) I've been using for some light-weight work. It
> has the nice property that `if´ is an expression. So I was wondering if
> this would be nice in D as well...
>
> int lim(int x, int a, int b)
> {
> return if (x < a)
> a
> else if (x > b)
> b
> else
> x;
> }
> ...
> Regards
> Bent
>
This is a feature that sounds like it *should* be useful, but
which I never seem to use in languages that have it. I'll use
the short form (a ? b : c) in very simple expressions, but
even there I won't nest the expressions.
I'd guess that I use select-case statements five times more
frequently, but it could be 10 times more frequently, and they
are a rarely used construct.
Seriously, if there were a parallel-execution for-loop
construction I'd probably use it more often than I use a
nested if expression. (I feel that there *OUGHT* to be a
parallel execution for-loop expression, which really means a
for-loop where the different iterations can be run in random
order and unsynchronized, but which will all be completed by
the time the end of the loop is reached. That's what I wanted
foreach to mean.)
More information about the Digitalmars-d
mailing list