I'm trying to work with some vectors and have run into a strange problem. An obvious way to define a difference of two vectors would be
dif[x_,y_] := x-y
I thought an equivalent way of doing this would be
dif[x_,y_] := Table[x-z,{z,{y}}][[1]]
However, using this second method, there is some strange behaviour. When I evaluate
dif[{x,z},{0,0}]
I get the result
{x,{0,0}}
which is clearly not what I wanted.
If I try evaluating
dif[{x,y},{0,0}]
instead, everything is ok, which leads me to think that the variable z in my definition of dif is treated as non-local. This seems pretty counterintuitive to me, as I was expecting z to act as a dummy variable.
What am I missing?
One solution that works is using Module. This is a bit unsatisfying though, as it seems to me z should be treated as local even without having to explicitly demand this.