Now that macros are more like generic functions than ever, I kept thinking if there was a reason why we didn’t have terse syntax for defining macros, ie:
julia> isint(x::Int) = true
isint (generic function with 1 method)
julia> isint(2)
true
julia> @isint(x::Int) = true
@isint (macro with 1 method)
julia> @isint 2
true
Instead of:
macro isint(x::Int) true end
Maybe short macro definitions are not that common, but I keep seeing them in string macros for example and other simple macros:
macro raw_str(s::AbstractString); s; end
@raw_str(s::AbstractString) = s
macro thingy_str(s::ASCIIString); do_my_ascii_thing!(s); end
@thingy_str(s::ASCIIString) = do_my_ascii_thing!(s)
I know this is being picky, but I didn’t find a previous discussion about this open for discussion. So what do you think guys?
julia> fooERROR: UndefVarError: foo not definedin eval(::Module, ::Any) at ./boot.jl:229julia> macro x(y) y end@x (macro with 1 method)julia> @x(foo) = 123123julia> foo123
Ismael Venegas Castelló Data Analyst Cel. 044 55 6434 0229 | Cerro San Francisco 357, C.P. 04200 Campestre Churubusco, Coyoacán Ciudad de México |
Tel. 6718 1818 richit.com.mx |