[Prev][Next][Index][Thread]

Re: zero? & 0 | 1



On 13 Mar 2000 11:15:00 +0100, "Gabor Greif" <gabor@no.netopia.com> wrote:

> I like the idiomatic expression
> 
> bool-value? & 0 | 1
> 
> as a shorthand for if-then-else.
> 
> For filing a bug in an open-source Dylan implementation :-) I need
> confirmation that the above expression evaluates to 0 for bool-value? == #t
> and 1 for bool-value? == #f
> 
> The reasoning is that binary operators are evaluated from left to right and
> &, | only evaluate their rhs if necessary.
> 
> Can somebody confirm this?

Seems to work as you'd want in FD 2.

BTW you could always wrap up the expression in a macro, e.g.

? define macro either { either(?c, ?t, ?f) } => { ?c & ?t | ?f } end macro;
No values

either(#t, 0, 1);
  $4 = 0

either(#f, 0, 1);
  $5 = 1




Follow-Ups: References: