It's a side effect of short-circuit evaluation<http://docs.julialang.org/en/latest/manual/control-flow/#man-short-circuit-evaluation>for && and || but it's not spelled out explicitly. Perhaps a note about this somewhat idiomatic way of doing things should be mentioned.
On Wed, Mar 19, 2014 at 5:49 PM, <[email protected]> wrote: > Nice tip. > > Can you point out where does this trick appear in the documentation? > > Luis > > > On Wednesday, March 19, 2014 2:59:10 PM UTC-6, Steven G. Johnson wrote: >> >> On Wednesday, March 19, 2014 11:33:57 AM UTC-4, Cristóvão Duarte Sousa >> wrote: >>> >>> Sometimes I see myself writing one line if-elses like `if x<0 x=-x end`, >>> which I think is not very "readable". >>> >> >> Of course, in this particular case you could just do x = abs(x), but a >> typical style for one-line if-then in Julia is to use &&: >> >> n == 0 && return 0 >> n < 0 && throw(BoundsError()) >> >> or in this case >> >> x < 0 && (x = -x) >> >
