# Defining function inside a macro

**URL:** <https://discourse.julialang.org/t/defining-function-inside-a-macro/9139>\
**Category:** General Usage\
**Created:** [February 18, 2018, 3:58am UTC](https://discourse.julialang.org/t/defining-function-inside-a-macro/9139 "2018-02-18T03:58:08Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [February 18, 2018, 4:28am UTC](https://discourse.julialang.org/t/defining-function-inside-a-macro/9139/4 "2018-02-18T04:28:16Z")

</div>

Next challenge… Is it possible to define the function with custom number of args? maybe I would have to mess with the AST?

```julia
# @makefn "fn" "hello" :a :b :c
# => fn_hello(a,b,c) = sum([a,b,c])
macro makefn(prefix, name, args...)
    fn = Symbol(prefix * "_" * name)
    argstup = Tuple(args)
    quote
        function $(esc(fn))($(esc(argstup)))
            sum([$(esc(argstup))])
        end
    end
end

```

```julia
syntax: "(Expr(:quote, :a)::Any, Expr(:quote, :b)::Any, Expr(:quote, :c)::Any)" is not a valid function argument name

```

---

_[View the full topic](https://discourse.julialang.org/t/defining-function-inside-a-macro/9139)._
