MathGroup Archive 2002

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

Search the Archive

Re: Newbie-type question: structured data types in Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37537] Re: Newbie-type question: structured data types in Mathematica?
  • From: Tom Burton <tburton at brahea.com>
  • Date: Mon, 4 Nov 2002 02:43:55 -0500 (EST)
  • References: <aq2l8n$g10$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 11/3/02 12:03 AM, in article aq2l8n$g10$1 at smc.vnet.net, "David Park"
<djmp at earthlink.net> wrote:

> CircleType = {{_, _}, _};
> ConstructCircle[position : {_, _}, radius_] := {position, radius}
> GetRadius[circle : CircleType] := Part[circle, 2]
> GetPosition[circle : CircleType] := Part[circle, 1]
> Attributes[SetRadius] = {HoldFirst};
> SetRadius[circle_][radius_] := (circle = ReplacePart[circle, radius, 2];)

It's easy to type a little stronger:

circleType = circle[{_, _}, _];
constructCircle[position : {_, _}, radius_] := circle[position, radius];
positionGet[circle : circleType] := Part[circle, 1];
radiusGet[circle:circleType] := Part[circle, 2];
positionSet[circle_][
    position:{_,_}] := (circle = ReplacePart[circle, position, 1])
radiusSet[circle_][radius_] := (circle = ReplacePart[circle, radius, 2]);
(Attributes[#] = {HoldFirst})&/@{positionSet,radiusSet};

I avoid capitalizing circle to prevent shadowing (clashing names with)
context System`. 

Tom Burton


  • Prev by Date: Re: Overlay ListDensityPlot and Value
  • Next by Date: Re: line wrapping
  • Previous by thread: Re: RE: Newbie-type question: structured data types in Mathematica?
  • Next by thread: Re: Newbie-type question: structured data types in Mathematica?