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

Reusing function names keeps potting "old" function #508

Closed
denglerchr opened this issue Sep 28, 2016 · 4 comments
Closed

Reusing function names keeps potting "old" function #508

denglerchr opened this issue Sep 28, 2016 · 4 comments

Comments

@denglerchr
Copy link

`t = linspace(0, 10, 100)
f(x) = x
plot(t, f); gui()
print("Press Enter for 2nd plot"); readline()

now i want a quadratic plot

f(x) = x^2
plot(t, f); gui()`

Hello, i keep having troubles when redefining functions and plotting them. The plot function does not seem to realise the redefinition and keeps plotting the "old" function. E.g. in the example above, the linear function is plotted twice, instead of the quadratic plot. I'm using Julia 0.5.0 and Plots 0.9.3

@denglerchr
Copy link
Author

Oh boy, my code got destroyed, here again safe mode for better copy paste:

t = linspace(0, 10, 100)
f(x) = x
plot(t, f); gui()
print("Press Enter for 2nd plot"); readline()

f(x) = x^2
plot(t, f); gui()

@KristofferC
Copy link
Contributor

KristofferC commented Sep 28, 2016

This is not Plots fault:

JuliaLang/julia#18076
JuliaLang/julia#265

etc. For some reason this got worse on 0.5.

@tbreloff
Copy link
Member

Yeah that's weird... I can reproduce. Note that if you don't do that first plot command then the second plot works. Glad to hear it's not my fault :)

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Sep 28, 2016

Yeah, it's a Base thing. It also messes up on conditionals:

JuliaLang/julia#16965
JuliaLang/julia#15602

It's because of how they changed function compilation in v0.5. The easy answer is, if you want to overwrite f, just make it an anonymous function.

f = (x) -> x^2

Then you can overwrite it without worry. In v0.5, anonymous functions compile so there's no performance loss by doing this.

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

4 participants