So I have this macro:
macro partial(call)
Expr(:function, :((rest...,)), Expr(:call, call.args..., :(rest...)))
end
for partial function application.
timestwo = @partial *(2)
timestwo(5) # 10; works fine
rest = 7 # name `rest` clashes with parameter name in function generated by macro.
timesrest = @partial *(rest)
timesrest(5) # MethodError: no method matching *(::Tuple{Int64}, ::Int64)
if I esc
the second expression (Expr(:function, :((rest...,)), esc(Expr(:call, call.args..., :(rest...))))
) then it ignores the value of the parameter and uses the captured rest
twice.
What is the best solution here? Is copying the args off the call even correct?
Thanks!
EDIT: I have misunderstood the use of esc
as it is made to violate hygiene. eval
solves the proble of name clashing, but when the variable rest
is changed between the creation of timesrest
and its invocation, the old value is used.