Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

copying a variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92293] copying a variable
  • From: ramiro <ramiro.barrantes at uvm.edu>
  • Date: Sat, 27 Sep 2008 06:47:43 -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. So that the output should be:

4
2

Thanks in advance,
Ramiro


  • Prev by Date: Re: Curious on the .nb format Opções
  • Next by Date: Re: How to do symbolic matrix manipulations
  • Previous by thread: Re: Curious on the .nb format Opções
  • Next by thread: Copying a variable