Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Assigning values to elements of a list within functions' topicStudent Support Forum > General > Archives > "Assigning values to elements of a list within functions"

Next Comment >Help | Reply To Topic
Author Comment/Response
Jeffrey
01/31/01 12:50pm

Working with Mathematica 4.0.1.0 for Students, I have been having problems assigning values to list elements within a user-defined function. For example:

listone = {1, 1, 1, 1}

f[x_List] := x[[1]] = 0

f[listone]

And the error message I get:

Set::''setps'': ''\!\({1, 1, 1, 1}\) in assignment of part is not a symbol.''

Performing the operation outside a function is obviously no problem:

listone[[1]] = 0

0

listone

{0, 1, 1, 1}

Similar attempts to reassign values are also unsuccessful within functions, such as:

h[x_List] := Do[x[[2]]++, {i, 1, 5}]

Is this just not allowed? Is there a better way to go about this?

URL: ,

Subject (listing for 'Assigning values to elements of a list within functions')
Author Date Posted
Assigning values to elements of a list within f... Jeffrey 01/31/01 12:50pm
Re: Assigning values to elements of a list with... Forum Modera... 01/31/01 5:34pm
Next Comment >Help | Reply To Topic