I'm trying to write a macro for generation of new functions given their 
name and arguments, e.g. given macro call: 

@deffun foo(a, b)

it should generate function like: 

function foo(a, b)
    # do some stuff                                                         
                                                                            
             
end

Important part is that both - name of a function and name of arguments - 
should be preserved. My best attempt to do it looks like this: 

macro deffun(ex)
    func = ex.args[1]
    args = ex.args[2:end]
    return quote
        function $(esc(func))($(esc(args...)))
            # do some stuff                                                 
                                                                            
              
        end
    end
end

`$(esc(func))` works pretty well, but `args` isn't a Symbol and so macro 
compilation fails. 

1. How do I escape list of arguments here? 
2. How do I make this macro to also support argument types? E.g. given 
macro call: 


@deffun foo(a::Int, b::Float64)

the following functions should be generated: 

function foo(a::Int, b::Float64)
    # do some stuff                                                         
                                                                            
             
end



Reply via email to