I use the macro below for a partial evaluation for a Macro to serialize a linear solver code.
The code change is done on the string form.
Can the macro be written without converting forth and back?
Got lost in quoting and escaping.
macro mint(e)
@show e.args # [:A, :i, :j]
s = string(e) # Expr -> String
s = replace(s, "i" => "\$i") # replace index names by their interpolation
s = replace(s, "j" => "\$j")
s = replace(s, "k" => "\$k")
s = ":($s)" # quote to keep expression
e = Meta.parse(s) # String -> Expr
@show e.args # [:(A[$(Expr(:$, :i)), $(Expr(:$, :j))])]
quote
$(esc(e))
end
end
i =1; j = 2
A = rand(2,2)
@mint A[i, j] # :(A[1, 2])