Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'r[[1]]="A" OK at top level but not in function?' topicStudent Support Forum > General > Archives > "r[[1]]="A" OK at top level but not in function?"

Next Comment >Help | Reply To Topic
Author Comment/Response
Sophi
02/03/12 4:41pm

Newbie here. Please excuse incorrect terminology I might use here ...

Below I can assign a field of a record at the top level at In[2], but I cannot do what looks like the very same assignment via a function call at In[5]. Why is this? Yes, I see the "is not a symbol" error but don't understand it. Thanks!!

In[1]:= r = rec["a",1]
Out[1]= rec[a,1]
In[2]:= r[[1]] = "b"
Out[2]= b
In[3]:= r
Out[3]= rec[b,1]
In[4]:= f[x_] := x[[1]] = "c"
In[5]:= f[r]
During evaluation of In[5]:= Set::setps: rec[b,1] in the part assignment is not a symbol. >>


URL: ,

Subject (listing for 'r[[1]]="A" OK at top level but not in function?')
Author Date Posted
r[[1]]="A" OK at top level but not in function? Sophi 02/03/12 4:41pm
Re: r[[1]]= Nasser M. Ab... 02/04/12 6:00pm
Next Comment >Help | Reply To Topic