RE: Newbie-type question: structured data types in Mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg37533] RE: [mg37521] Newbie-type question: structured data types in Mathematica?
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 3 Nov 2002 02:59:10 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Ken, You are rather edging into OO programming, of which there has been some discussion on this news group in the past week or so. Perhaps there is room for something like a StructuredData package that would be considerably less than OO but serve a useful purpose. In any case, you could do something like the following where I define a CircleType data item and a few routines for manipulating it. 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];) mycircle = ConstructCircle[{1, 2}, 3]; GetRadius[mycircle] 3 GetPosition[mycircle] {1, 2} SetRadius[mycircle][3.5] GetRadius[mycircle] 3.5 etc. I hope you get some other good discussion of this because it is a very useful question. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Kenneth McDonald [mailto:kmmcdonald at wisc.edu] To: mathgroup at smc.vnet.net I've been looking for a while, and I can't find a way to create any sort of structured data type in Mathematica, i.e. one with named fields that contain other values. Does such a beast exist? Thanks for the help, Ken McDonald kmmcdonald at wisc.edu
- Follow-Ups:
- Re: RE: Newbie-type question: structured data types in Mathematica?
- From: "Hermann Schmitt" <schmitther@netcologne.de>
- Re: RE: Newbie-type question: structured data types in Mathematica?