Skip to content

Usage outside REPL #194

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

Closed
geluso opened this issue Sep 17, 2018 · 5 comments
Closed

Usage outside REPL #194

geluso opened this issue Sep 17, 2018 · 5 comments

Comments

@geluso
Copy link

geluso commented Sep 17, 2018

Does Revise only work in the REPL? The docs say "the changes will be incorporated into the very next command you issue from the REPL."

I'm trying to write a program (ultimately drawing to Canvas) where I want the program to execute changes in a file while the program is still running. For instance look at the following.

Is it possible to run julia Try.jl which spins in the while loop printing out forever, then editing Example.jl and having the main program print out the changed contents?

Example.jl

function hello(str)
  println("Hello ", str)
end

Try.jl

using Revise

Revise.includet("./Example.jl")
while true
  hello("world")
  Revise.revise()
end
@timholy
Copy link
Owner

timholy commented Sep 19, 2018

Did you try it? There's no cost to try 😄.

@timholy
Copy link
Owner

timholy commented Sep 19, 2018

Oh, you mean, "can you display the diff"? Yes, but not without editing Revise. If that's all you want to do, you're better off using FileWatching and then shelling out to diff directly.

@geluso
Copy link
Author

geluso commented Sep 19, 2018

Yes I've tried it and I absolutely love how Revise works in the REPL. Sorry for the phrasing. I'm not interested in the diff. I mean I want the output of the program to change so it executes new code when I edit the other file.

Revise works absolutely well when I'm in the REPL and I edit a file between commands. What I'm trying to do here is get it to react to changes while a program is running with a while loop. I want the program to detect and execute the code without having to restart the program so it never leaves the while loop. It just runs the new code inside the modified function.

$ julia Try.jl
Hello world
Hello world
Hello world
Hello world
Hello world
Goodbye world         << edit hello function inside Example.jl and save so it has "println("Goodbye ", str)"
Goodbye world
Goodbye world
^C

@timholy
Copy link
Owner

timholy commented Sep 19, 2018

Got it. Just change your loop to

while true
    Base.invokelatest(hello, "world")
    Revise.revise()
end

If you're curious, the issue is one regarding "world age".

@geluso
Copy link
Author

geluso commented Sep 19, 2018

That works! Thank you and thanks for pointing me toward World Age.

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

2 participants