I am trying to understand Metaprogramming in Julia. I wrote the following code
function traversal!(x::Expr,mem)
for xx in x.args
if isa(xx,Expr)
push!(mem,xx)
traversal!(xx,mem)
end
end
end
expr=:(sum((x-cos(W2*sin(W1*x+b1)+b2))^2))
mem=[]
a=traversal!(expr,mem)
I expect mem to be an Array with 8 elements
:((x - cos(W2 * sin(W1 * x + b1) + b2)) ^ 2)
:(x - cos(W2 * sin(W1 * x + b1) + b2))
:(cos(W2 * sin(W1 * x + b1) + b2))
:(W2 * sin(W1 * x + b1) + b2)
:(W2 * sin(W1 * x + b1))
:(sin(W1 * x + b1))
:(W1 * x + b1)
:(W1 * x)
Result is as expected however when i replace the expression
expr=:(sum((x-cos(W2*sin(W1*x+b1)+b2))^2))
with
expr=:(sum((x-cos.(W2*sin.(W1*x+b1)+b2)).^2))
output becomes
:((x - cos.(W2 * sin.(W1 * x + b1) + b2)) .^ 2)
:(x - cos.(W2 * sin.(W1 * x + b1) + b2))
:(cos.(W2 * sin.(W1 * x + b1) + b2))
:((W2 * sin.(W1 * x + b1) + b2,))
:(W2 * sin.(W1 * x + b1) + b2)
:(W2 * sin.(W1 * x + b1))
:(sin.(W1 * x + b1))
:((W1 * x + b1,))
:(W1 * x + b1)
:(W1 * x)
Why do i get those extra Tuple Symbols?