# \#scope

**URL:** https://discourse.julialang.org/tag/scope/198.md?match_all_tags=true&page=3&tags%5B%5D=scope

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 4

---

## [Scope of a script file](https://discourse.julialang.org/t/scope-of-a-script-file/16791)

<div class="topic-metadata">

**Author:** [@Vic](https://discourse.julialang.org/u/Vic)\
**Replies:** 5\
**Last updated:** [October 25, 2018, 8:01pm UTC](https://discourse.julialang.org/t/scope-of-a-script-file/16791 "2018-10-25T20:01:56Z")

</div>

Does a script (as opposed to a module or function) introduce any scope, global or local ? If used with include("myscript") I understood that no new scope is introduced as per Essentials · The Julia Language And neith…

---

## [Weird scoping issue](https://discourse.julialang.org/t/weird-scoping-issue/14162)

<div class="topic-metadata">

**Author:** [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Replies:** 5\
**Last updated:** [August 28, 2018, 12:09pm UTC](https://discourse.julialang.org/t/weird-scoping-issue/14162 "2018-08-28T12:09:52Z")

</div>

using Julia v"1.0.0", julia\> count = 0 0 or julia\> count count (generic function with 6 methods) julia\> count = 0 ERROR: cannot assign variable Base.count from module Main Why is it that the function is not exported…

---

## [Scope of a begin (and if) block](https://discourse.julialang.org/t/scope-of-a-begin-and-if-block/13811)

<div class="topic-metadata">

**Author:** [@mtgd](https://discourse.julialang.org/u/mtgd)\
**Replies:** 2\
**Last updated:** [August 21, 2018, 9:09am UTC](https://discourse.julialang.org/t/scope-of-a-begin-and-if-block/13811 "2018-08-21T09:09:48Z")

</div>

Consider the following code, which results in 3 being printed: x = 3 begin local x x = 4 end println(x) In the documentation about Scope of Variables it says “the begin construct does not introduce a new sco…

---

## [How to get current module/scope in macro](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310)

<div class="topic-metadata">

**Author:** [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Replies:** 2\
**Last updated:** [August 12, 2018, 4:53pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13310 "2018-08-12T16:53:34Z")

</div>

Hi, community. Could I get the module or scope of the calller of macro in Julia1.0? Just like this: module SomeModule macro f() S = caller\_module.eval(:S) fields = fieldnames(S) # do something with fields …

---

## [How to get current module/scope in macro](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13309)

<div class="topic-metadata">

**Author:** [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Replies:** 1\
**Last updated:** [August 12, 2018, 4:53pm UTC](https://discourse.julialang.org/t/how-to-get-current-module-scope-in-macro/13309 "2018-08-12T16:53:33Z")

</div>

Hi, community. Could I get the module or scope of the calller of macro in Julia 1.0? Just like this: module SomeModule macro f() S = caller\_module.eval(:S) fields = fieldnames(S) # do something with fields…

---

## [Same code in if and else blocks, get UndefVarError only on else condition](https://discourse.julialang.org/t/same-code-in-if-and-else-blocks-get-undefvarerror-only-on-else-condition/11611)

<div class="topic-metadata">

**Author:** [@mwolters](https://discourse.julialang.org/u/mwolters)\
**Replies:** 3\
**Last updated:** [June 13, 2018, 10:11am UTC](https://discourse.julialang.org/t/same-code-in-if-and-else-blocks-get-undefvarerror-only-on-else-condition/11611 "2018-06-13T10:11:42Z")

</div>

Suppose I have a function with 2 arguments, and I want to make a new function with one of the arguments fixed to a value, depending on some condition. For example: fun(x,a) = a\*x function foo(flag::Bool) if flag …

---

## [Possibility of \`local import\` statements in future?](https://discourse.julialang.org/t/possibility-of-local-import-statements-in-future/10611)

<div class="topic-metadata">

**Author:** [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Replies:** 63\
**Last updated:** [May 2, 2018, 9:54pm UTC](https://discourse.julialang.org/t/possibility-of-local-import-statements-in-future/10611 "2018-05-02T21:54:28Z")

</div>

Is there any possibility that Julia will have local import in the future? I’m aware some people think this is a silly idea; however, this would actually solve a very real problem some users might face. Namely, people wa…

---

## [Scope and global in REPL (julia 0.7)](https://discourse.julialang.org/t/scope-and-global-in-repl-julia-0-7/10233)

<div class="topic-metadata">

**Author:** [@oheil](https://discourse.julialang.org/u/oheil)\
**Replies:** 3\
**Last updated:** [April 9, 2018, 2:53pm UTC](https://discourse.julialang.org/t/scope-and-global-in-repl-julia-0-7/10233 "2018-04-09T14:53:22Z")

</div>

x=1; while x\<10 x+=1 end ┌ Warning: Deprecated syntax \`implicit assignment to global variable \`x\`\`. │ Use \`global x\` instead. └ @ nothing none:0 I think while should not open a new scope of variables. In more comple…

---

## [Using variables from call space in macro return execution](https://discourse.julialang.org/t/using-variables-from-call-space-in-macro-return-execution/8616)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 18\
**Last updated:** [January 27, 2018, 8:47am UTC](https://discourse.julialang.org/t/using-variables-from-call-space-in-macro-return-execution/8616 "2018-01-27T08:47:23Z")

</div>

TL DR: I have a macro in an external module, how do I enable the expression it executes after “return” to see variables declared in the scope in which the macro is called? Background at the end if you are interested. I …

---

## [How does scope work for declaring functions](https://discourse.julialang.org/t/how-does-scope-work-for-declaring-functions/8474)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 12\
**Last updated:** [January 22, 2018, 10:37am UTC](https://discourse.julialang.org/t/how-does-scope-work-for-declaring-functions/8474 "2018-01-22T10:37:54Z")

</div>

I have not found any good resources on this. I cannot find anything helpful in the Julia docs entry on scopes. However I have had problems with it and found enough instances were I have no idea what is going on and would…

---

## [Make functions in modules use functions in global scope](https://discourse.julialang.org/t/make-functions-in-modules-use-functions-in-global-scope/8481)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 6\
**Last updated:** [January 19, 2018, 8:48pm UTC](https://discourse.julialang.org/t/make-functions-in-modules-use-functions-in-global-scope/8481 "2018-01-19T20:48:53Z")

</div>

I have this module: export test\_func function test\_func() return funk(x) end end and I have this program funk(x) = 2 test\_func() which gives the error UndefVarError: funk not defined. Is there a …

---

## [Variable scope in functions](https://discourse.julialang.org/t/variable-scope-in-functions/7876)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 8\
**Last updated:** [December 21, 2017, 3:54am UTC](https://discourse.julialang.org/t/variable-scope-in-functions/7876 "2017-12-21T03:54:12Z")

</div>

I don’t know what to make of this… In the follow snippet const user\_mappings, profile\_mappings = Dict{Int,Int}(), Dict{Int,Int}() const user\_counter, profile\_counter = 0, 0 function data\_accessor() :: DataAccessor t…

---

## [Global variable disappears](https://discourse.julialang.org/t/global-variable-disappears/4021)

<div class="topic-metadata">

**Author:** [@ulysses](https://discourse.julialang.org/u/ulysses)\
**Replies:** 2\
**Last updated:** [May 31, 2017, 7:09pm UTC](https://discourse.julialang.org/t/global-variable-disappears/4021 "2017-05-31T19:09:02Z")

</div>

I have the following scenario for initialization of a global variable which fails for some mysterious reason. // t.jl n = 1 function f() if n == 1 n = 2 end println(n) end ... julia\> include("t.jl") …

[Previous page](https://discourse.julialang.org/tag/scope/198.md?match_all_tags=true&page=2&tags%5B%5D=scope)
