Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Function Fun' topicStudent Support Forum > General > "Function Fun"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Nasser M. Abbasi
11/13/12 00:03am

funcTest[list_List, str_String, count_Integer] := list[[count]] = str

list1={a,b}

funcTest[list1,"Help",1]
Results in:
{a, b}
Set::setps: {a,b} in the part assignment is not a symbol. >>
Yet,
list1[[1]]="Help!!"
{Help!!,b}
Works. What is the problem?

-----------------------------------

Mathematica passes things by value. You can't update a function parameter.

To update an input, you must first make a copy of it, then update the copy, and return the copy.

-------------------
funcTest[list_List,str_String,count_Integer]:=Module[{c=list},

c[[count]]=str;
c
]

list1={a,b};
list1=funcTest[list1,"Help",1]
----------------------

{"Help", b}



URL: ,

Subject (listing for 'Function Fun')
Author Date Posted
Function Fun CCOsborn 11/12/12 1:56pm
Re: Function Fun Michael 11/12/12 9:02pm
Re: Function Fun Nasser M. Ab... 11/13/12 00:03am
< Previous CommentHelp | Reply To Comment | Reply To Topic