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

Passing redefined function as argument #18353

Closed
mortenpi opened this issue Sep 4, 2016 · 9 comments
Closed

Passing redefined function as argument #18353

mortenpi opened this issue Sep 4, 2016 · 9 comments

Comments

@mortenpi
Copy link
Contributor

mortenpi commented Sep 4, 2016

The following code, where we pass a function as an argument, redefine it and pass it again,

q(n) = 0
@show map(q, 1:1)
q(n) = 1
@show map(q, 1:1)

doesn't work as expected on 0.5 and 0.6, outputting:

map(q,1:1) = [0]
WARNING: Method definition q(Any) in module Main at ...
map(q,1:1) = [0]

I am guessing it's due to #265 and the fact that every function is a separate type now.

However, unlike most of #265, it's a regression compared to 0.4, since there we get what we would expect:

map(q,1:1) = [0]
map(q,1:1) = [1]

Sorry if this has already been discussed, but I was not able to find any mention of this. I do feel that perhaps this is something that should be addressed in 0.5, since the regression makes REPL work a bit more tedious.

@yuyichao
Copy link
Contributor

yuyichao commented Sep 4, 2016

Dup of #265

@yuyichao yuyichao closed this as completed Sep 4, 2016
@yuyichao
Copy link
Contributor

yuyichao commented Sep 4, 2016

And your case is discussed in #265 already #265 (comment)

@mortenpi
Copy link
Contributor Author

mortenpi commented Sep 4, 2016

Sorry, missed that. However, will the fix of #265 get backported to 0.5 as well? It only has the 0.6 milestone at the moment.

@yuyichao
Copy link
Contributor

yuyichao commented Sep 4, 2016

No this is unlikely going to be fixed in 0.5.

@mortenpi
Copy link
Contributor Author

mortenpi commented Sep 4, 2016

In that case I would maintain that it's somewhat of an annoying regression compared to 0.4 😞. At least for me the REPL workflow where I keep redefining functions in the global scope is pretty common.

@mortenpi
Copy link
Contributor Author

mortenpi commented Sep 4, 2016

Should it at least be mentioned in NEWS.md? And while there is a WARNING now, perhaps that could be made more informative, stating something along the lines of "already called/compiled functions using this function or receiving it as an argument, will still use the old definition and hence may not work as expected".

@tkelman
Copy link
Contributor

tkelman commented Sep 7, 2016

sure. fastest way would be to propose a wording which we could iterate on in a PR

@cstjean
Copy link
Contributor

cstjean commented Sep 7, 2016

Is there any work-around?

@iamed2
Copy link
Contributor

iamed2 commented Sep 7, 2016

The workaround would be to use anonymous functions:

julia> q(n) = 0
q (generic function with 1 method)

julia> map(x->q(x), 1:1)
1-element Array{Int64,1}:
 0

julia> q(n) = 1
WARNING: Method definition q(Any) in module Main at REPL[1]:1 overwritten at REPL[5]:1.
q (generic function with 1 method)

julia> map(x->q(x), 1:1)
1-element Array{Int64,1}:
 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants