From: Logan Capaldo Date: 2005-05-12T08:35:33+09:00 Subject: Re: alternatives to ? : contruct On 5/11/05, Logan Capaldo wrote: > On 5/11/05, David A. Black wrote: > > Hi -- > > > > On Thu, 12 May 2005, Logan Capaldo wrote: > > > > > On 5/11/05, John-Mason P. Shackelford wrote: > > >> As an alternative to: > > >> > > >> a = y == z ? b : c > > >> > > >> we can say: > > >> > > >> a = (b if y == x) || c > > >> > > >> Can anyone think of others? > > > > > > Heres one way: > > > > > > x == y and a = b or c > > > > In the case where x != y, that expression will just return c, without > > assigning it to a. (I learned this the hard way either here or on IRC > > recently :-) > > > > David > > > > -- > > David A. Black > > dblack@wobblini.net > > > > > > Yeah, that was the the point. > > If (x == y) then a = b else c end > is equivalent to x == y and a = b or c > if you wanted to assign to a the result of the expression just like a ?: you'd do a = (y == x and b) or c unfortunately you have to use the parens in this case you could also do y == x and a = b or a = c