You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that you cannot invoke a macro as @foo{...} — you have to do @foo {...}. Can we remove the requirement of a space before the brace? This would be useful for macros to construct parameterized types, for example.
Background: In a recent discourse discussion, I was looking at implementing a macro @NamedTuple that allows you to write @NamedTuple{raw::Vector{Float64}, value::Int} as a synonym for NamedTuple{(:raw, :value),Tuple{Array{Float64,1},Int64}}, via the implementation:
macro NamedTuple(ex)
Meta.isexpr(ex, :braces) || error("@NamedTuple expects {...}")
all(e -> Meta.isexpr(e, :(::)), ex.args) || error("@NamedTuple a sequence of name::type expressions")
vars = [QuoteNode(e.args[1]) for e in ex.args]
types = [e.args[2] for e in ex.args]
return :(NamedTuple{($(vars...),), Tuple{$(types...)}})
end
This works with @NamedTuple {raw::Vector{Float64}, value::Int}, but omitting the space gives
Haha, I knew this didn't work in <=1.4 so I thought I'd just PR a fix for it directly... but for some reason couldn't find the right place in the source.
I noticed that you cannot invoke a macro as
@foo{...}
— you have to do@foo {...}
. Can we remove the requirement of a space before the brace? This would be useful for macros to construct parameterized types, for example.Background: In a recent discourse discussion, I was looking at implementing a macro
@NamedTuple
that allows you to write@NamedTuple{raw::Vector{Float64}, value::Int}
as a synonym forNamedTuple{(:raw, :value),Tuple{Array{Float64,1},Int64}}
, via the implementation:This works with
@NamedTuple {raw::Vector{Float64}, value::Int}
, but omitting the space givesSince this is currently a syntax error (that is, parsing fails), supporting it would be non-breaking.
The text was updated successfully, but these errors were encountered: