The := operator isn't spoken for yet, although it's been considered for in-place assignment for arrays. These could be seen to dovetail in the sense that the x := operator could both be allowed to mutate its LHS object and rebind its LHS but only if the LHS is already defined. The reason they kind of match up is that you can mutate something that hasn't already been assigned – sketchy perhaps.
However, I have to say that as soon as you have to worry about = versus := I feel like you might as well just declare variables (which I also don't want to have to do). I would prefer to have opt-in (but easy to use) code analysis that can tell you that "anwser" is an unused variable (or in slight variations of this code, that "answer" or "anwser" is always or sometimes not assigned). On Fri, Mar 7, 2014 at 11:23 AM, David Moon <[email protected]> wrote: > In Julia-0.3.0-prerelease-d2d9bd93ed.app on Mac OS X 10.6: > > The following test case was boiled down from a much larger piece of code. > > function f(x) > answer = false > if (x > 10) > anwser = true > end > return answer > end > > does not issue any warnings, and always returns false. Shouldn't it warn > that anwser is defined as a local variable but never read? > > Is there a way to do an assignment to an existing local variable without > the possibility of declaring a new one, to avoid the possibility of bugs > like this as well as clarify the intention of the code? Is := already > used? In testing := behaves strangely, not similar to :+ which is quote of > +, so I am not sure what := means now. If I could have written > > function f(x) > answer = false > if (x > 10) > anwser := true > end > return answer > end > > and had it say "anwser is not a known variable" my problem would have > been obvious. >
