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

remove superfluous global keywords in scope docs #56762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ArnoStrouwen
Copy link
Contributor

These global keywords seem like a remnant from when soft/hard scope worked differently.
I find the tutorial clearer without them.

@inkydragon inkydragon added the docs This change adds or pertains to documentation label Dec 6, 2024
@MasonProtter
Copy link
Contributor

MasonProtter commented Dec 6, 2024

I think this is a bad idea because soft scope only works in the REPL (another mistake IMO, but long since passed). If someone used that code in a script, package or even eval, it'd not work.

Compare:

julia> begin
           Fs = Vector{Any}(undef, 2)
           i = 1
           while i <= 2
               Fs[i] = () -> i
               i += 1
           end
           Fs[1]()
       end
3

versus

julia> @eval begin
           Fs = Vector{Any}(undef, 2)
           i = 1
           while i <= 2
               Fs[i] = () -> i
               i += 1
           end
           Fs[1]()
       end
┌ Warning: Assignment to `i` in soft scope is ambiguous because a global variable by the same name exists: `i` will be treated as a new local. Disambiguate by using `local i` to suppress this warning or `global i` to assign to the existing global variable.
└ @ REPL[24]:6
ERROR: UndefVarError: `i` not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.
Stacktrace:
 [1] top-level scope
   @ REPL[24]:5
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:430
 [3] top-level scope
   @ REPL[24]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants