Revise.jl icon indicating copy to clipboard operation
Revise.jl copied to clipboard

Exported variables not cleared in namespace

Open w-hc opened this issue 3 years ago • 6 comments

Hi thanks for the amazing package! I am new to Revise. This might be a known limitation. If I add a function name to the exported variable list, and then delete it, that variable name is still exposed.

on REPL I type

using Revise
using Example

and modify the Example package by adding functions f and g

module Example
export hello, domath, f, g

"""
    hello(who::String)

Return "Hello, `who`".
"""
hello(who::String) = "Hello, $who"

"""
    domath(x::Number)

Return `x + 5`.
"""
domath(x::Number) = x + 5


f() = π

g() = 2 * π

end

Everything works as expected. Now if I remove g from export list,

...
export hello, domath, f  # g is removed
...

The function g can still be accessed. Let me know if this is a known problem that cannot be easily circumvented. Thank you!

w-hc avatar Jun 14 '21 12:06 w-hc

Thanks for the comment! Yes, this is a Julia limitation. It would be nice to fix, though.

timholy avatar Jul 18 '21 10:07 timholy

And if you edit "hello", if you are using it has:

using Example

hello()

The output won't be updated.

It works only with:

using Example # import/using doesn't matter what do you use since you have to specify the module

Example.hello()

raythurnvoid avatar Sep 02 '23 19:09 raythurnvoid

For me (and I think many others), the module-scoping isn't necessary. Can you be more explicit about what you're doing? I'm guessing you redefined the Example module (e.g., include("example.jl")). But Revise doesn't require you to do that, and indeed it's much better not to do that. Just using/import your packages and edit them without explicitly reloading any files. If this doesn't work for you then maybe you're on a file system where FileWatching fails and you need to turn on polling (see the docs).

timholy avatar Sep 03 '23 16:09 timholy

For me (and I think many others), the module-scoping isn't necessary. Can you be more explicit about what you're doing? I'm guessing you redefined the Example module (e.g., include("example.jl")). But Revise doesn't require you to do that, and indeed it's much better not to do that. Just using/import your packages and edit them without explicitly reloading any files. If this doesn't work for you then maybe you're on a file system where FileWatching fails and you need to turn on polling (see the docs).

maybe is a dumb question, how to you import a module you have in a custom file under your src? i thought you are forced to "include" the file first.

This is exactly what I'm doing:

# main.jl
using Revise

include("./example.jl")
using .Example

hello()
# Hello world!
# example.jl
module Example
export hello

function hello()
    println("Hello world!")
end

end

I edit example.jl to print just "Hello" but I can't make hello() print the new value without specifying the module in the main.jl

I've tried all the combinations:

  • execute main.jl -> edit -> execute main.jl including using Revise
  • execute main.jl -> edit -> execute main.jl excluding using Revise
  • execute main.jl -> edit -> execute main.jl excluding using Revise and include("./example.jl")
  • execute main.jl -> edit -> execute main.jl including using Revise but excludinginclude("./example.jl")

I'm doing everything in the REPL basically pressing ctrl+enter with the vscode extension I've killed the REPL at each try.

raythurnvoid avatar Sep 03 '23 18:09 raythurnvoid

includet("./example.jl") (note the t)

timholy avatar Sep 05 '23 16:09 timholy

includet("./example.jl") (note the t)

Thank you! it works, I've read the docs but i didn't quite get what was the purpose of includet

raythurnvoid avatar Sep 07 '23 02:09 raythurnvoid