Why do string macros in Julia use ...? -
i looking @ source r_str
macro in julia, parses r"text"
regex("text")
. sec argument flags...
, passes flags regex, i
case insensitive, , on.
i playing myself , got:
julia> macro a_str(p, flags...) print(flags) p end julia> a"abc"iii ("iii",)"abc"
so seems iii
passed in first flag. in case, why there ...
on flags. possible pass in more 1 element of flags
macro?
the reason because macro gets invoked 1 argument when a"xyz"
written or 2 arguments when a"xyz"bc
written. doing flags...
in macro signature, can handle both. if macro expanders generic functions 1 have default value sec argument aren't generic, they're anonymous, , way handle different numbers of arguments anonymous functions varargs.
macros julia-lang julia-macros
No comments:
Post a Comment