Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Modifying list passed as argument' topicStudent Support Forum > General > "Modifying list passed as argument"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Peter Pein
09/19/09 7:34pm

Hi,

sth. like a=5 is done by Mathematica via calling Set[a,5]. The function Set has the attribute HoldFirst set. You can ensure to get the second element of your list in the call to Set by "Evaluate"ing lst[[2]] first:
In[1]:= test[list_]:=Block[{x=2},Evaluate[list[[2]]]=x];
lst={a,b,c};
test[lst];
lst
Out[4]= {a,2,c}

Peter


URL: ,

Subject (listing for 'Modifying list passed as argument')
Author Date Posted
Modifying list passed as argument qj 09/16/09 4:52pm
Re: Modifying list passed as argument Peter Pein 09/19/09 7:34pm
Re: Re: Modifying list passed as argument qj 09/21/09 3:17pm
Re: Modifying list passed as argument yehuda ben-s... 09/24/09 02:26am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic