MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List of Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15251] Re: List of Matrices
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 28 Dec 1998 02:37:49 -0500
  • References: <764t8l$bjh@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The entry
    exp[[index]]= rhs
works  only if expr is a symbol with immediate value (given by = and not
:=) having a position index.
This behavour is made possible by Set and SetDelayed both holding their
first place and being able to examine it before deciding what to do.
Neither expr nor expr[[index]] are evaluated but the stored value of
expr is altered directly (this be very efficient)

The following works
a= {1};
?a
"Global`a"
a = {1}
a[[1]] =2;
?a
"Global`a"
a = {2}
If a[[1]] were were evaluatad in the process then we would have got 1
=2, which would not be  accepted.

The following are examples of failure.

a[[2]] =3;
Set::"partw": "Part \!\(2\) of \!\({2}\) does not exist."

and

a[[1,2]]=3;
Set::"partd":
    "Part specification \!\(a \\[LeftDoubleBracket] \(1, 2\) \
\\[RightDoubleBracket]\) is longer than depth of object."


b:={1};

b[[1]] =3;
Set::"noval":
  "Symbol \!\(b\) in part assignment does not have an immediate value."

c[1]={1};

c[[1]]=3;
Set::"noval":
  "Symbol \!\(c\) in part assignment does not have an immediate value."


Here is an extra check that expr[[index]] is not evaluated. d =
{Unevaluated[x=4]};

?d
"Global`d"
d = {Unevaluated[x = 4]}
d[[1]]= 3;

d has been changed

?d
"Global`d"
d = {3}

But x = 4 has not been evaluated
x
x



Peter wrote in message <764t8l$bjh at smc.vnet.net>...
>I have the following sequence of commands:
>
>In[108]:=
>s=IdentityMatrix[2]
>
>Out[108]=
>{{1,0},{0,1}}
>
>In[110]:=
>ss[1]=s
>
>Out[110]=
>{{1,0},{0,1}}
>
>In[111]:=
>ss[1][[1,1]]
>
>Out[111]=
>1
>
>In[112]:=
>ss[1][[1,1]]=3
>
>Set::setps: ss[1] in assignment of part is not a symbol."
>
>Out[112]=
>3
>
>Why can I read the entry ss[1][[1,1]] but can not change its value ?
>What do I have to do to change this value ?
>
>Thank's (once more) for any help
>
>                                                    pedro
>
>
>



  • Prev by Date: Re: Matrix Problem
  • Next by Date: Re: Reading Mathematica 3.0 notebooks in Mathematica 2.2
  • Previous by thread: List of Matrices
  • Next by thread: Reading Mathematica 3.0 notebooks in Mathematica 2.2