It's simply an operator precedence[1] issue.  The assignment operator is 
one of the lowest precedence operations in Julia[2], so your expression is 
getting parsed as (boolexpr && boolvar) = false.  That's why the 
parentheses are required.

1. https://en.wikipedia.org/wiki/Order_of_operations
2. 
http://docs.julialang.org/en/release-0.3/manual/mathematical-operations/#operator-precedence


On Tuesday, April 7, 2015 at 9:49:23 AM UTC-4, David Gold wrote:
>
> Greetings all,
>
> I've quite taken to the short-circuit evaluation idiom. I just have a 
> quick question about its behavior. Why does
>
> boolexpr && boolvar = false
>
> throw an error ("syntax: invalid assignment location"), but
>
> boolexpr && (boolvar = false)
>
> work just fine? The documentation (
> http://docs.julialang.org/en/latest/manual/control-flow/#short-circuit-evaluation)
>  
> doesn't quite mention this point, though the parentheses are used in the 
> examples at the end of the section.
>
> I'm just curious. I don't have much background in programming (but will 
> have to, as I'm beginning graduate study in statistics this coming fall -- 
> I thought I'd be an early adopter of something for once), so please humor 
> me if this is a silly question.
>
> Thank you,
> D
>

Reply via email to