I want to build a constructor with keyword arguments inside a macro, and the first keyword argument should be for the expression. I find it difficult to put this expression in the expression. Here is what I mean. Say I have a type
type Test ex end
which contains the expression. I want to create a constructor where origex = :(a * b) is the default value from the keyword argument. I tried
@eval :(Test(ex=$origex) = Test(origex))
But if you look at an expression that does:
Test(ex=a * b) = begin # console, line 1: Test(origex) end
you will see that this will not work, because a*b should still be an expression. So I tried
@eval :(Test(ex=:($origex)) = Test(origex))
but it has an odd expression
Test(ex=$(Expr(:quote, :($(Expr(:$, :origex)))))) = begin
which will also not be eval . Instead, I need to get
Test(ex=:(a * b)) = begin # console, line 1: Test(origex) end
as an expression for eval, but I don't know how to get this expression in an expression.
source share