Closed
Description
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
julia> @NamedTuple{raw::Vector{Float64}, value::Int}
ERROR: syntax: invalid macro usage "@(NamedTuple{raw::Vector{Float64}, value::Int})"
Since this is currently a syntax error (that is, parsing fails), supporting it would be non-breaking.