Re: Partial evaluation
- To: mathgroup at smc.vnet.net
- Subject: [mg21172] Re: Partial evaluation
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 17 Dec 1999 01:22:54 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <8320dg$glm@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Kevin, In[]:=A = {{1, 1}, {2, 2}}; In[]:={{Hold[A], {2, 2}}, val} /. {{Hold[a_], index_}, v_} :> {Part[a, Sequence @@ index] = v} In[]:=A Out[]={{1, 1}, {2, val}} works nice. Hope that helps Jens Kevin Jaffe wrote: > > I'm sure this is a FAQ, but I haven't found the answer. > > First we define: > > In[1]:= A = {{0, 0}, {0, 0}} > > Out[1]= {{0, 0}, {0, 0}} > > > Then the following assignment works: > > In[2]:= Part[A, 1, 1] = 1 > > Out[2]= 1 > > In[3]:= A > > Out[3]= {{1, 0}, {0, 0}} > > But this one doesn't: > > In[4]:= Part@@{A, 1, 1} = 2 > > Set::write: Tag Apply in Part @@ {{{1, 0}, {0, 0}}, 1, 1} is Protected. > > Out[4]= 2 > > In[5]:= A > > Out[5]= {{1, 0}, {0, 0}} > > And this is even worse, of course: > > In[6]:= Evaluate[Part@@{A, 1, 1}] = 2 > > Set::setraw: Cannot assign to raw object 1. > > Out[6]= 2 > > In[7]:= A > > Out[7]= {{1, 0}, {0, 0}} > > I understand the reasons for the error messages, but I don't know how > to get around the problem. What I need is to partially evaluate the > left-hand side of In[4], but I don't know how to do this. > > The reason I want to do things like "Part@@{A, 1, 1} = 2" is that I'm > trying to write a module that must modify entries in an n_1 x n_2 x > ... x n_k array A of arbitrary dimension k. I can compute the desired > multi-index v = {i_1, i_2,..., i_k} for the array without knowing the > array's dimension, but I can't figure a way to assign to the > location A[[i_1, i_2, ..., i_k]]. > > Is there any way to do what I'm trying to do? > > Thanks! > > KJ > > LYCOShop is now open. On your mark, get set, SHOP!!! > http://shop.lycos.com/ > .