# Make a variable as a global variable within a function

**URL:** <https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067>\
**Category:** New to Julia\
**Tags:** macros\
**Created:** [June 17, 2021, 6:29am UTC](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067 "2021-06-17T06:29:58Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [June 17, 2021, 3:04pm UTC](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067/20 "2021-06-17T15:04:17Z")

</div>

Umm… actually I’m not familiar with macros.  
I think that it is enough to solve the below problem:

```julia
function _my_func(a, b)
    c = 2*a
    b = b + 1
    a + b
end

```

```julia
function my_func(a)
    b = a
    @log _my_func(a, b)
end

```

Then, the definition of `my_func` should be

```julia
function my_func(a)
    b = a
    # the content of `_my_func`. It must not change the above `b`... how?
    c = 2*a
    b = b + 1
    a+b
    #
end

```

Do you have any idea?

EDIT:  
Ah, generate a new function `_my_func __LOG__ ` and run it may work.  
But I don’t still know how to generate `_my_func __LOG__ ` as the following.  
This question is continued at [the next question](https://discourse.julialang.org/t/macro-trasnforming-a-function-call-to-a-new-function-definition-and-call-the-new-function/63100).

```julia
function my_func(a)
    b = a
    # the content of `_my_func`. It must not change the above `b`... how?
    function _my_func __LOG__ (a, b)
        c = 2*a
        b = b + 1
        a+b
    end
    _my_func __LOG__ (a, b)
    #
end

```

---

_[View the full topic](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067)._
