Supplying (x;y) as an argument is the same as supplying y #1345

pao opened this Issue Oct 7, 2012 · 3 comments


None yet
2 participants

pao commented Oct 7, 2012

I think I know what's going on here--x is evaluated for side-effects, its result discarded, then y returned. Unfortunately, randi() can take either a 2-tuple of integers or a single integer as first argument, and let's say I've been writing a lot of vector literals...

randi((-10, 10)) # correct
randi((-10; 10)) # will never return a negative number; equivalent to randi(10)
julia> (x -> x[2])((1,2))

julia> (x -> x[2])((1;2))
no method ref(Int64,Int64)
 in method_missing at base.jl:70
 in anonymous at no file

This seems like a bit of a trap, given the visual similarity of ; and ,. The interaction with randi() is worse, since the output is random anyways, you might not notice.


JeffBezanson commented Oct 7, 2012

I don't see that there is a fix for this except maybe to change randi.


JeffBezanson commented Oct 9, 2012

Another option is to give an error or warning for expressions in side-effect-only contex when they obviously have no effects (e.g. a number or symbol).

@ghost ghost assigned JeffBezanson Oct 9, 2012


JeffBezanson commented Jan 23, 2013

randi has been changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment