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

Variable Scope #38

Open
hdavid16 opened this issue Feb 12, 2021 · 2 comments
Open

Variable Scope #38

hdavid16 opened this issue Feb 12, 2021 · 2 comments

Comments

@hdavid16
Copy link

Can you explain better how to handle variable scope with @capture_out?

I tried a small example with the following script:

using Suppressor #import package
local y #define local variable
function f(x) #define function
    y = x^2
    println(y)
    return y
end

log = @capture_out y = f(2) #capture output

#print results
println("log: $log")
println("y = $y")

When I run the script from the REPL (i.e., include(script.jl)), I get the following:

log: 4

ERROR: LoadError: UndefVarError: y not defined
@hdavid16
Copy link
Author

I figured out how to work around this: initialize y before calling @capture_out. If I assign it some value, then the output of f(2) does get stored. Maybe mention this in the readme?

@nickbrady
Copy link

I figured out how to work around this: initialize y before calling @capture_out. If I assign it some value, then the output of f(2) does get stored. Maybe mention this in the readme?

I had the same issue and resolved it following your instructions. I created a PR to update the README.md.

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