As an exercise, I’m trying to make a macro that turns @x a b c
into a = b = c = 1234
.
I tried to write it recursively, but I don’t know how to fix my error
Definition:
julia> macro x(s::Symbol, ss...)
quote
$(esc(s)) = @x $(esc(ss))...
end
end
julia> macro x()
1234
end
Call:
julia> @x a b c
ERROR: LoadError: MethodError: no method matching @x(::LineNumberNode, ::Module, ::Expr)
Closest candidates are:
@x(::LineNumberNode, ::Module) at REPL[9]:2
@x(::LineNumberNode, ::Module, ::Symbol, ::Any...) at REPL[21]:2
in expression starting at REPL[21]:3
Any tips?
(The self-assigned exercise is to write it recursively)
7 posts - 5 participants