Thanks a lot to your help and your advice.
In broader context, my target is to creat a set of local varialbes. Firstly, create a NamedTuple came to my mind, but in practise, that is not convinient. So now I can get the target just like this:
macro localvars(expr)
bb=[]
for cc in expr.args
if cc isa Expr && cc.head==:(=)
append!(bb,[cc.args[1]])
end
end
cvv=Expr(:tuple,(:($x=$x) for x in bb)...)
bbres=quote
let
$expr
$cvv
end
end |> esc
end
vars=@localvars begin
a=1
b=2
c=a+b
end
vars.a
vars.c
This is a little convinient for me