Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3258 > unrolled thread

Re: Assigning part of indexed object

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-06-23 11:30 +0000
Last post2011-06-23 11:30 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Assigning part of indexed object Bill Rowe <readnews@sbcglobal.net> - 2011-06-23 11:30 +0000

#3258 — Re: Assigning part of indexed object

FromBill Rowe <readnews@sbcglobal.net>
Date2011-06-23 11:30 +0000
SubjectRe: Assigning part of indexed object
Message-ID<itv847$pcv$1@smc.vnet.net>
On 6/22/11 at 7:29 AM, fabrice.laussy@n0spam-gmail.com (Fabrice P.
Laussy) wrote:

>How do you set the part of an indexed object, say:

>m[1] = Range[5];

>is my indexed object (I could have m[2], etc.). Now I want to do
>something like:

>m[1][[1]] = 10;

>with effect of having m[1] read:

>{10, 2, 3, 4, 5}

>but of course the line above evaluates to 1 = 10.

>This could be achieved by having a non-indexed object get in the
>way, e.g., m1=m[1], assign m1 and then return to m[1]=m1, but I
>believe there should a more elegant way.

The key is understanding where the list {1,2,3,4,5} is stored.
You can change m such that m[1][[1]] evaluates to 10 as follows:

In[1]:= m[1] = Range[5];

In[2]:= m[1]

Out[2]= {1,2,3,4,5}

In[3]:= DownValues[m] = ReplacePart[DownValues[m], {1, 2, 1} -> 10];

In[4]:= m[1]

Out[4]= {10,2,3,4,5}


[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web