On Mon, Jul 27, 2015 at 6:31 PM, Yichao Yu <yyc1...@gmail.com> wrote:
> module Test
>
> export ffun
>
> macro protofun(fsig::Expr)
>     @assert fsig.head == :call
>     fname = fsig.args[1]
>     argnames = []
>     for idx in 2:length(fsig.args)
>         arg = fsig.args[idx]
>         if isa(arg, Expr) && arg.head == :kw
>             arg = arg.args[1]
>         end
>         if isa(arg, Symbol)
>             push!(argnames, arg)
>         elseif isa(arg, Expr) && arg.head == :(::)
>             if length(arg.args) != 2
>                 @gensym s
>                 insert!(arg.args, 1, s)
>             end
>             push!(argnames, arg.args[1])

I realized that I didn't handle vararg arguments... oh well...

>         end
>     end
>     body = quote
>         error(string("No matching of: ", $fname,
>                      ($([:(typeof($(esc(arg)))) for arg in argnames]...),)))
>     end
>     Expr(:function, esc(fsig), body)
> end
>
> "some doc"
> @protofun ffun(::Number, b::String, ::Int=1)
>
> Base.Test.@test (@doc ffun) !== nothing
>
> ffun(1, "")
>
> end
>
> On Mon, Jul 27, 2015 at 6:26 PM, Christoph Ortner
> <christophortn...@gmail.com> wrote:
>> Just one last question though:
>>
>> Is there a way to write the macro so that I could attach the doc strings as
>> usual, i.e.
>>
>> @doc doc"yads"->
>> @protofun(ffun, Integer, String)
>>
>> instead of
>>
>> @protofun(ffun, Integer, String, "yads")
>>
>> ? I couldn't figure this out at all.
>> Thanks,
>>   Christoph

Reply via email to