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: [mg37585] Re: Newbie-type question: structured data types in Mathematica?
  • From: Erich Mueller <emueller at mps.ohio-state.edu>
  • Date: Tue, 5 Nov 2002 05:04:00 -0500 (EST)
  • Organization: Ohio State University
  • References: <aq2l8n$g10$1@smc.vnet.net> <aq58jg$s7b$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

A third option, with advantages and disadvantages, is to use a list of
Rules for your structured data type, such as

structureddata[type->circle, position->{1,2}, radius->{3}]

I'll spare you the exercise of giving creation and reading rules.

Erich


On Mon, 4 Nov 2002, Tom Burton wrote:

> 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: Different EPS exported file from frontend and kernel
  • Next by Date: Re: Importing complex numbers into mathematica
  • Previous by thread: Re: Newbie-type question: structured data types in Mathematica?
  • Next by thread: Re: Newbie-type question: structured data types in Mathematica?