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

scope of keyword argument default values #17240

Closed
longqian95 opened this issue Jul 2, 2016 · 7 comments
Closed

scope of keyword argument default values #17240

longqian95 opened this issue Jul 2, 2016 · 7 comments
Assignees
Labels
design Design of APIs or of the language itself keyword arguments f(x; keyword=arguments) kind:breaking This change will break code
Milestone

Comments

@longqian95
Copy link
Contributor

a=1
f(;a=a)=a
f() will generate "UndefVarError" error.
There is no problem if it is a normal argument.

@dhoegh
Copy link
Contributor

dhoegh commented Jul 2, 2016

Could you provide the output of versioninfo(), as i cannot reproduce the error. I can reproduce this on master. The reason for the error is it gets lowered to something like the following:

a=1
function test()
      a=a
end
test()

This will also fail with an UndefVarError. I think this have been discussed somewhere, and is intended behavior. If it should work for the keyword argument then it would require some special lowering around https://github.com/JuliaLang/julia/blob/master/src/julia-syntax.scm#L427.

@longqian95
Copy link
Contributor Author

I think whether it is intended or not, f(a=a) and f(;a=a) should be consistent: both are OK or both are error. Current situation is confusing.

@ivarne
Copy link
Sponsor Member

ivarne commented Jul 5, 2016

+1 for consistent behaviour. (obviously)

@ivarne
Copy link
Sponsor Member

ivarne commented Jul 5, 2016

Tentativly marking this as a regression due for 0.5.

@ivarne ivarne added the kind:regression Regression in behavior compared to a previous version label Jul 5, 2016
@ivarne ivarne added this to the 0.5.0 milestone Jul 5, 2016
@cstjean
Copy link
Contributor

cstjean commented Jul 5, 2016

+1 for consistency too, but it fails on Julia 0.4.5, so it's not a regression. Furthermore, the docs say it's intended behaviour

Optional and keyword arguments differ slightly in how their default values are evaluated. When optional argument default expressions are evaluated, only previous arguments are in scope. In contrast, all the arguments are in scope when keyword arguments default expressions are evaluated.

I don't understand why all keyword arguments are in scope if their value is undefined...

@ivarne ivarne removed the kind:regression Regression in behavior compared to a previous version label Jul 5, 2016
@ivarne ivarne removed this from the 0.5.0 milestone Jul 5, 2016
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Jul 6, 2016
@StefanKarpinski
Copy link
Sponsor Member

I'm all for changing this in the future, but it will have to be in 0.6.

@StefanKarpinski StefanKarpinski added kind:breaking This change will break code design Design of APIs or of the language itself labels Jul 6, 2016
@JeffBezanson JeffBezanson changed the title keyword argument causes "UndefVarError" error scope of keyword argument default values Sep 12, 2016
@JeffBezanson JeffBezanson self-assigned this Sep 12, 2016
@tkelman tkelman modified the milestones: 1.0, 0.6.0 Jan 5, 2017
@JeffBezanson JeffBezanson added the keyword arguments f(x; keyword=arguments) label Jul 20, 2017
@JeffBezanson
Copy link
Sponsor Member

Resolved: change to "let*" (successive nested scopes) scoping.

JeffBezanson added a commit that referenced this issue Jul 25, 2017
JeffBezanson added a commit that referenced this issue Jul 25, 2017
This matches the behavior of optional positional arguments.
JeffBezanson added a commit that referenced this issue Jul 25, 2017
This matches the behavior of optional positional arguments.
JeffBezanson added a commit that referenced this issue Jul 26, 2017
This matches the behavior of optional positional arguments.
JeffBezanson added a commit that referenced this issue Jul 26, 2017
This matches the behavior of optional positional arguments.
JeffBezanson added a commit that referenced this issue Jul 26, 2017
fix #17240, evaluate keyword argument defaults in successive scopes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of APIs or of the language itself keyword arguments f(x; keyword=arguments) kind:breaking This change will break code
Projects
None yet
Development

No branches or pull requests

7 participants