From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd40601768eaf8fd X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Array of Variant Records Question... Date: 1999/09/13 Message-ID: <37dd87b2@news1.prserv.net>#1/1 X-Deja-AN: 524671530 Content-transfer-encoding: 7bit References: <7r5vh3$imu1@svlss.lmms.lmco.com> <37d6a45c@news1.prserv.net> <37d6ccb6@news1.prserv.net> <7r77i8$i08$1@nnrp1.deja.com> <37d7c116@news1.prserv.net> <7r8t21$ov5$1@nnrp1.deja.com> <37dcf193@news1.prserv.net> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 13 Sep 1999 23:24:34 GMT, 129.37.62.170 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-09-13T00:00:00+00:00 List-Id: In article , Robert A Duff wrote: > Have you considered: > > type And_Exp(L, R : access Bool_Exp'Class) is > new Bool_Exp with null record; > > ? No, not here, though I've used this technique for another pattern (the Command pattern). >> function New_And >> (L, R : access Bool_Exp'Class) >> return Bool_Exp_Access is >> >> use And_Exp_Storage; >> >> Exp : constant Exp_Access := New_Exp; >> -- type Exp_Access is access all And_Exp; >> begin >> Exp.L := Bool_Exp_Access (L); -- (1) >> Exp.R := Bool_Exp_Access (R); -- (2) >> >> return Bool_Exp_Access (Exp); -- (3) >> end New_And; > > Something's wrong with that. How can New_Exp know to allocate an > And_Exp record? New_Exp is provided by a private generic storage manager that looks like this: private generic type Exp_Type is new Bool_Exp with private; package Bool_Exps.Storage is type Exp_Access is access all Exp_Type; function New_Exp return Exp_Access; procedure Do_Free (Exp : access Exp_Type); end Bool_Exps.Storage; The package is instantiated like this: package And_Exp_Storage is new Storage (And_Exp); > And the "Exp.L" and "Exp.R" are illegal, because > there's (presumably) no such components? I'm confused. Yes, there are L and R components. Here's what an And_Exp looks like: type And_Exp is new Bool_Exp with record L, R : Bool_Exp_Access; end record; You need New_Exp to return the specific type, precisely to give you access to the representation of the type. But after you fill in the components, you have to (manually) convert it back to the class-wide root type. > How about: > > return new Bool_Exp'(Bool_Exp_Access(L), Bool_Exp_Access(R)); > > which avoids the need for one of the conversions? But I think you really meant: return new And_Exp'(...); In my implementation, all allocation goes through some storage manager. (There's a separate instantiation for each specific type in the class.) I'll be discussing the Interpreter pattern in my upcoming Design Patterns tutorial at this year's SIGAda conference. You're going to be there too, right? Maybe you and I can finally get to meet face-to-face... Matt