In Macros for numerical performance: Horner’s methodhttps://github.com/stevengj/18S096-iap17/blob/master/lecture4/Metaprogramming.ipynb, macro hornor is defined as follows:
copied from base/math.jl
macro horner(x, p...)
ex = esc(p[end])
for i = length(p)-1:-1:1
ex = :( $(esc(p[i])) + t * $ex )
end
Expr(:block, :(t = $(esc(x))), ex)
end
so why use a new variable t
in for loop, and after the loop still use Expr(...)
, not just defined the hornor as follows:
macro horner2(x, p...)
ex = esc(p[end])
for i = length(p)-1:-1:1
ex = :( $(esc(p[i])) + x * $ex )
end
ex
end