Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

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

Search the Archive

Copying a variable

  • To: mathgroup at
  • Subject: [mg92338] Copying a variable
  • From: Ramiro <ramiro.barrantes at>
  • Date: Sat, 27 Sep 2008 22:23:22 -0400 (EDT)

This must be very simple.  Consider the following code:

k[1] = 2;
sub[x_] := With[{z = x}, z[1] = 4; z]
r = sub[k];

The output is

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,

  • Prev by Date: Re: Redirecting input
  • Next by Date: Re: Redirecting input
  • Previous by thread: copying a variable
  • Next by thread: Re: copying a variable