# How to call arguments from outside of the scope

**URL:** <https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752>\
**Category:** General Usage\
**Tags:** scope, functions\
**Created:** [September 25, 2021, 2:37pm UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752 "2021-09-25T14:37:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakub\_Mitura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakub_mitura/32/19496_2.png) [@Jakub\_Mitura](https://discourse.julialang.org/u/Jakub_Mitura)\
**Post date:** [September 25, 2021, 2:37pm UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752/1 "2021-09-25T14:37:56Z")

</div>

Hello is it possible to invoke a function to use variable from caller function scope using macros ? I think about sth like

> function innerFunction()  
> println(a\*4)  
> end
> 
> function outerContext()  
> a = 4  
> @useOutArgs innerFunction()  
> end
> 
> macro useOutArgs(ex)  
> return esc(:($ex))
> 
> end

> outerContext()#return a not defined - I would like for it to print 16

Now Is it possible to modify useOutArgs macro to print 16 without passing a to arguments ?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 25, 2021, 3:12pm UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752/2 "2021-09-25T15:12:46Z")

</div>

No - only variables of the scope the function is defined in are accessible. You can’t use variables of a “sibling scope”. This is unrelated to macros, as they only transform some code into some other code. Scope is a semantic concept, while macros operate only on syntax.

What are you trying to achieve in the grand scheme of things? Is there a reason you can’t pass the variable into the called function directly?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 25, 2021, 3:14pm UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752/3 "2021-09-25T15:14:51Z")

</div>

You could define the inner function inside the outer function and then it would have access to the variables of the outer function.

---

<div class="post-metadata">

**Author:** ![Jakub\_Mitura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakub_mitura/32/19496_2.png) [@Jakub\_Mitura](https://discourse.julialang.org/u/Jakub_Mitura)\
**Post date:** [September 26, 2021, 4:04am UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752/4 "2021-09-26T04:04:27Z")

</div>

I have quite nested function a lot of times i need to pass the variable from top function through all intermidiate to the bottom (most nested) and in all of this passing frequently i mess the order of positional arguments as there is no possibility of named arguments, and arguments list become big part of a code

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [September 26, 2021, 8:55am UTC](https://discourse.julialang.org/t/how-to-call-arguments-from-outside-of-the-scope/68752/5 "2021-09-26T08:55:35Z")

</div>

Use closures: [https://m3g.github.io/JuliaNotes.jl/stable/closures/](https://m3g.github.io/JuliaNotes.jl/stable/closures/)
