# Create any functions with a macro, the functions can call each other

**URL:** <https://discourse.julialang.org/t/create-any-functions-with-a-macro-the-functions-can-call-each-other/78113>\
**Category:** General Usage\
**Created:** [March 18, 2022, 10:42pm UTC](https://discourse.julialang.org/t/create-any-functions-with-a-macro-the-functions-can-call-each-other/78113 "2022-03-18T22:42:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [March 18, 2022, 10:42pm UTC](https://discourse.julialang.org/t/create-any-functions-with-a-macro-the-functions-can-call-each-other/78113/1 "2022-03-18T22:42:02Z")

</div>

hello, i need to create any functions with a macro, the functions can call each other. What am I doing wrong ?

```julia
macro macr(ClassName::Symbol)
    local Class = @eval $ClassName
    return esc(quote
        foo(::Type{$ClassName}) = $(2 + 2)
        bar(::Type{$ClassName}) = $(foo(Class) + 2)
    end)
end

@macr Int # -> **LoadError: UndefVarError: foo not defined**

```

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [March 18, 2022, 11:10pm UTC](https://discourse.julialang.org/t/create-any-functions-with-a-macro-the-functions-can-call-each-other/78113/2 "2022-03-18T23:10:27Z")

</div>

Is this

```julia
macro macr(ClassName::Symbol)
    local Class = @eval $ClassName
    return esc(quote
        foo(::Type{$ClassName}) = $(2 + 2)
        bar(::Type{$ClassName}) = (foo($Class) + 2)
    end)
end

@macroexpand (@macr Int)

```

yielding

```julia
quote
    foo(::Type{Int}) = begin
            4
        end
    bar(::Type{Int}) = begin
            foo(Int64) + 2
        end
end

```

what you want?

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [March 19, 2022, 6:09am UTC](https://discourse.julialang.org/t/create-any-functions-with-a-macro-the-functions-can-call-each-other/78113/3 "2022-03-19T06:09:04Z")

</div>

i want result of `foo(Int64) + 2`

```julia
quote
    foo(::Type{Int}) = begin
            4
        end
    bar(::Type{Int}) = begin
            6
        end
end

```
