Skip to content

Commit

Permalink
Add description of local kw in global scope (JuliaLang#42794)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtuamnuq authored and nickrobinson251 committed Jan 14, 2022
1 parent 45d70fe commit 8047a9b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/src/manual/variables-and-scoping.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ julia> module E
ERROR: cannot assign variables in other modules
```

If a top-level expression contains a variable declaration with keyword `local`,
then that variable is not accessible outside that expression.
The variable inside the expression does not affect global variables of the same name.
An example is to declare `local x` in a `begin` or `if` block at the top-level:

```jldoctest
julia> x = 1
begin
local x = 0
@show x
end
@show x;
x = 0
x = 1
```

Note that the interactive prompt (aka REPL) is in the global scope of the module `Main`.

## Local Scope
Expand Down

0 comments on commit 8047a9b

Please sign in to comment.