On Thu, Apr 26, 2012 at 10:31:46AM -0400, Brad Baxter wrote:
> On 4/25/12, David Nicol <davidnicol@gmail.com> wrote:
> > The proposal appears to be, allow
> >
> > if ( BOOLEAN ) { TRUE BRANCH } else { FALSE BRANCH }
> >
> > and variations (unless, elsif, elsunless (do we even have that?) and so on)
> >
> > to act as R-values in assignment and elsewhere. In effect, making that
> > syntax exactly a long way to write the ternary operator.
> >
> > An if-statement already sort of returns a value, but it can only be
> > captured by enclosing the if-statement in a block of some kind, so the
> > value gets returned
> > according the "value of a block is the value of the last expression
> > executed" rule.
>
> If I'm following, the initial challenge is recognizing when an
> 'if(unless)/elsif/else' construct is intended to be an expression
> (EXPR).
>
> If that hurdle is passed, then I suppose you could pretend you had a
> 'do{if...}' and get an R-value. But what if you pretend you had a
> (possibly nested) ternary? Wouldn't that buy you an L-value, too?
And then we can finally do what ALGOL could 40+ years ago:
if (CONDITION1) {$foo} else {$bar} = if (CONDITION2) {1} else {2};
Abigail
Thread Previous
|
Thread Next