Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't warn if _ is used twice #18251

Closed
StefanKarpinski opened this issue Aug 26, 2016 · 7 comments
Closed

don't warn if _ is used twice #18251

StefanKarpinski opened this issue Aug 26, 2016 · 7 comments
Labels
speculative Whether the change will be implemented is speculative
Milestone

Comments

@StefanKarpinski
Copy link
Sponsor Member

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.

@StefanKarpinski StefanKarpinski added the speculative Whether the change will be implemented is speculative label Aug 26, 2016
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Aug 26, 2016
@stevengj
Copy link
Member

It's not currently a warning, though, it's an error, no?

@JeffBezanson
Copy link
Sponsor Member

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.

@StefanKarpinski
Copy link
Sponsor Member Author

That would be fine with me as well.

@cortner
Copy link

cortner commented Aug 27, 2016

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 _.

@essenciary
Copy link

essenciary commented Aug 28, 2016

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.

@JeffBezanson
Copy link
Sponsor Member

Closing as duplicate of #9343

@Keno
Copy link
Member

Keno commented Oct 13, 2016

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

6 participants