Re: data structure / object
- To: mathgroup at smc.vnet.net
- Subject: [mg16411] Re: data structure / object
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Sat, 13 Mar 1999 02:21:33 -0500
- Organization: University of Western Australia
- References: <7bt50n$nbn@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
schatzi wrote: > I would to do the following with Mathematica 3.0 : > > Define a data structure, fot example point[x,y], and then overload > operators, and in particular the output operator. > > That is to say to be able to write > p=point[1,2];q=point[-1,3];r=p+q > pt[0,5] You can use UpSet (or UpSetDelayed) to do what you want: In[1]:= pt[a_,b_]+pt[c_,d_] ^:= pt[a+c,b+d] In[2]:= p=pt[1,2]; q=pt[-1,3]; r=p+q Out[2]= pt[0, 5] In[3]:= ?UpSetDelayed lhs^:=rhs assigns rhs to be the delayed value of lhs, and associates the assignment with symbols that occur at level one in lhs. > Thank you very much for your solutions, (and pointers to books/ > references). I suggest that you look up UpSet in the on-line Help. Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________