Copying a variable
- To: mathgroup at smc.vnet.net
- Subject: [mg92338] Copying a variable
- From: Ramiro <ramiro.barrantes at gmail.com>
- Date: Sat, 27 Sep 2008 22:23:22 -0400 (EDT)
Hello,
This must be very simple. Consider the following code:
k[1] = 2;
sub[x_] := With[{z = x}, z[1] = 4; z]
r = sub[k];
r[1]
k[1]
The output is
4
4
I would like to have the assignment inside the function (on z) don't
affect the parameter (x). I would like to copy x so that whatever
assignment I do on z doesn't affect it, in other words, I would like
to return _a copy_ of x.
Thanks in advance,
Ramiro