Thanks. Created PR 6819 <https://github.com/JuliaLang/julia/pull/6819> based on this discussion.
On Monday, May 12, 2014 8:23:38 AM UTC-7, Stefan Karpinski wrote: > > Yes, you're right. The last value in a conditional chain can be anything > and it will be evaluated and returned or not depending on the preceding > conditionals – which must be boolean if they are evaluated. > > > On Mon, May 12, 2014 at 11:18 AM, Peter Simon <[email protected]<javascript:> > > wrote: > >> I see that the following is a common idiom in Julia: >> >> ... >> flag = true >> ... >> flag && (x = rand(2,2)) >> ... >> >> which is very handy and concise, but seems to contradict the restriction >> stated in the >> documentation<http://docs.julialang.org/en/latest/manual/control-flow/?highlight=short%20circuit#short-circuit-evaluation>: >> >> "Just like condition expressions used in if, elseif or the ternary >> operator, the operands of && or|| must be boolean values (true or false). >> Using a non-boolean value is an error". Should the documentation be >> amended here? Is any kind of assignment allowed on the RHS, as long as it >> is enclosed in parentheses? What about other kinds of statements on the >> RHS? I note that if the positions of the two operands of && above are >> reversed, an error is generated, complaining about a non-boolean type used >> in a boolean context. >> >> --Peter >> >> >
