https://groups.google.com/forum/#!topic/julia-users/8S41r1KjdC4
How about not emitting this warning in the case where the variable name used twice is _
? I'm not proposing making _
special in any other way – just skipping this warning for it.
It's not currently a warning, though, it's an error, no?
I don't think we should make this a special case unless we go all the way to making _
mean "ignore". Otherwise we have to say what it means when e.g. two arguments have the same name. For example, we might say the value you get is the rightmost one, but we have to be sure to obey this everywhere in the compiler and I don't think that's worth it. But having a bitbucket variable could have real benefits.
That would be fine with me as well.
The real confusion for me was that for (t, _, _) in zip(x, y, z)
is fine while maximum( t for (t,_,_) in zip(x,y,z) )
is not. Personally, I really liked being able to use multiple _
.
One of the idiomatic Julia things is to leave out the variable name and only keep the type hint, as in:
foo(::SomeType) = 42
so this works:
foo(::SomeType, ::SomeType) = 84
"Yes, but what if one does not want to explicitly use types?", I hear you say.
This works too,
julia> f(::) = println("ah!")
f (generic function with 1 method)
although not as (I) expected, because:
julia> h(::, ::) = println("dude!")
ERROR: syntax: function argument names not unique
So Julia takes "::" to be the actual variable name, rather than an unnamed variable of type Any
.
But this works entirely fine:
julia> h(::Any, ::Any) = println("dude!")
h (generic function with 1 method)
I realize that many functional programming languages use _
to designate unused variable(s), but it seems to me that in Julia things would be more consistent and idiomatic if it would use ::
to designate unnamed variables of type Any
.
Closing as duplicate of #9343
Opened #18912 for the ::
parsing issue, so f(::) = println("ah!")
would be disallowed, and the correct way to write this would be f(_)
(potentially after #9343).
Most helpful comment
I don't think we should make this a special case unless we go all the way to making
_
mean "ignore". Otherwise we have to say what it means when e.g. two arguments have the same name. For example, we might say the value you get is the rightmost one, but we have to be sure to obey this everywhere in the compiler and I don't think that's worth it. But having a bitbucket variable could have real benefits.