MathGroup Archive 1998

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

Search the Archive

operator overloading with UpValues (eg, for shifting graphics)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13618] operator overloading with UpValues (eg, for shifting graphics)
  • From: Daniel Reeves <dreeves at flip.eecs.umich.edu>
  • Date: Fri, 7 Aug 1998 03:08:20 -0400
  • Organization: University of Michigan EECS
  • Sender: owner-wri-mathgroup at wolfram.com

I thought it would be nice to shift some graphics by just adding an x-y
pair.  It seemed like this sort of thing should do that:

Unprotect[Line];
Line /: Line[pts_] + {x_,y_} := Line[pts+{x,y}] Protect[Line];

But it doesn't.  The UpValue for Graphics doesn't get used. This does
work:

Line /: Line[pts_] + shift[x_,y_] := Line[pts+{x,y}]

but then I might as well just do this:

shift[Line[pts_],{x_,y_}] := Line[pts+{x,y}]

The idea is to be able to just say Line[...] + {x,y} and get a shifted
Line.

Does anyone know a way to do that?
Also, if/why Mathematica is doing "the right thing" in defying my
expectations in the first example.  Ie, should the Listable-ness of
Plus have precedence over my UpValue for Line?

Thanks,
Daniel

--
Daniel Reeves  dreeves at umich.edu 
http://ai.eecs.umich.edu/people/dreeves

"This isn't right.  This isn't even wrong." 
  -- Wolfgang Pauli, on a paper submitted by a physicist colleague



  • Prev by Date: Re: Does Mathematica speed up with multiple processors under NT?
  • Next by Date: Re: Mandelbrot
  • Previous by thread: Re: Does Mathematica speed up with multiple processors under NT?
  • Next by thread: Re: operator overloading with UpValues (eg, for shifting graphics)