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

fix @manipulate hygiene and add a test #185

Merged
merged 8 commits into from
Sep 26, 2017
Merged

Conversation

rdeits
Copy link
Contributor

@rdeits rdeits commented Sep 21, 2017

@manipulate was escaping too many things, which meant that it relied on the user having done using Interact and using Reactive. This change removes that requirement, and will also prevent weird errors in the case that a user has some local function called signal or preserve.

Fixes #184
Also fixes #156

@rdeits
Copy link
Contributor Author

rdeits commented Sep 21, 2017

Dang, I think I'm running into https://discourse.julialang.org/t/problem-with-escaping-anonymous-function-expressions-and-let-blocks/1314 and thus JuliaLang/julia#16096 (comment)

I'll try a different approach...

Edit: nope, not those issues

@rdeits
Copy link
Contributor Author

rdeits commented Sep 21, 2017

Ok, instead of escaping less, we can interpolate more. Hopefully this will work on 0.5-0.7

Edit: no, that wasn't actually the problem

@rdeits
Copy link
Contributor Author

rdeits commented Sep 21, 2017

Ah, never mind. That "invalid let syntax" shows up with Interact.jl master, so I won't worry about it for this PR.

Edit: the invalid let syntax was actually JuliaLang/julia#21774 . I've added an explicit version check to get the tests working in all supported versions.

@rdeits
Copy link
Contributor Author

rdeits commented Sep 21, 2017

Actually, the let syntax issue was pretty easy to work around. Tests are now passing on Julia v0.5, v0.6, and v0.7. I haven't actually got a working IJulia in v0.7, so I don't know if the widgets work, but this is at least an improvement over master

@JobJob JobJob merged commit 8444e57 into JuliaGizmos:master Sep 26, 2017
@JobJob
Copy link
Member

JobJob commented Sep 26, 2017

Thanks! Just one question, when I run this in IJulia:

using Interact: @manipulate

# Dummy implementations that should never be called:
signal(x...) = error("I (signal) should not be called")
preserve(x...) = error("I (preserve) should not be called")

@manipulate for i in 1:10, j in ["x", "y", "z"]
    2 * i, j * " hello"
end

It errors with "I (preserve) should not be called", is that expected?

@rdeits
Copy link
Contributor Author

rdeits commented Sep 26, 2017

Uh, I see that too. That's...baffling. Running macroexpand shows:

macroexpand(:(@manipulate for i in 1:10, j in ["x", "y", "z"]
    2 * i, j * " hello"
            end))
:(let i = (Interact.widget)(1:10, "i"), j = (Interact.widget)(["x", "y", "z"], "j")
        display(i)
        display(j)
        (Interact.preserve)((Interact.map)(((i, j)->begin  # In[3], line 8:
                        (2i, j * " hello")
                    end), (Interact.signal)(i), (Interact.signal)(j), typ=Interact.Any))
    end)

which seems to clearly show that Interact.preserve will be called. I'm so confused...

@rdeits
Copy link
Contributor Author

rdeits commented Sep 26, 2017

Oh now I see. The error isn't coming from the call to preserve inside manipulate, but instead from a different call to preserve in Interact/src/IJulia/setup.jl, line 81. I don't know much about that file, but the way it's written it will just call whatever preserve() is defined in the user's workspace. That's probably worth fixing too :)

@JobJob
Copy link
Member

JobJob commented Sep 26, 2017

Nice, yeah that makes sense.

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

Successfully merging this pull request may close these issues.

Macro hygiene issue in @manipulate "preserve not defined" when using Interact outside of ipython notebook
2 participants