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"

Next Comment >Help | Reply To Topic
Author Comment/Response
qj
09/16/09 4:52pm

I need to modify a list passed as an argument to a function.

Take the following code:

test[list_] := Block[{x = 2}, list[[2]] = x];
lst = {a, b, c};
test[lst];
lst

Here is its output:

During evaluation of In[13]:= Set::setps: {1,2,3} in the part assignment is not a symbol. >>

{a, b, c}

I would want to see {a,2,c}. How do I make functions that can do this?

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
Next Comment >Help | Reply To Topic