Re: Defining an UpValue for a specific List?
- To: mathgroup at smc.vnet.net
- Subject: [mg23203] Re: [mg23153] Defining an UpValue for a specific List?
- From: Bojan Bistrovic <bojanb at python.physics.odu.edu>
- Date: Mon, 24 Apr 2000 01:12:09 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
> Hello,
>
> I would like to make the following definition:
>
> df[[a_, b_]] ^:= DFPart[df, a_, b_]
>
> where df is a list of three components.
>
> I get the folowing error:
>
> UpSetDelayed::write: Tag List in {<<l>>}[[a_,b_]] is Protected.
>
> Is there a possibility to redefine Part[] for some symbols?
>
> Please email directly to
> schnoerr at mailzone.com
>
> Thank you very much!
>
> Claudius
>
Here's a different approach: define the funcion "MyPart" with properties
you like, and then use MakeExpression to reinterpret the sequence
df[[a,b]] as MyPart[df,a,b]:
In[1]:= MakeExpression[ RowBox[{aaa_,"[",RowBox[{"[",bbb_String,"]"}],"]"}],
StandardForm]:=
MakeExpression[ RowBox[{"MyPart","[",aaa,",",bbb,"]"}],StandardForm]
In[2]:= MakeExpression[ RowBox[{aaa_,"[",RowBox[{"[",
RowBox[{bbb___}],"]"}],"]"}],
StandardForm]:=
MakeExpression[ RowBox[{"MyPart","[",aaa,",",bbb,"]"}],StandardForm]
It's not a general solution to the problem since it will only work if
you're using Graphical Front End, but it might be enough.
Bojan
--
---------------------------------------------------------------------
Bojan Bistrovic, bojanb at jlab.org
Old Dominion University, Norfolk VA & Jefferson Lab, Newport News, VA
---------------------------------------------------------------------