From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: how do i implement double-dispatching?
Date: Tue, 23 Dec 2003 12:03:32 +0100
Date: 2003-12-23T12:03:32+01:00 [thread overview]
Message-ID: <bs9728$akeii$1@ID-77047.news.uni-berlin.de> (raw)
In-Reply-To: pan.2003.12.22.21.47.20.435399@yahoo.com
cl1motorsports wrote:
> On Mon, 22 Dec 2003 16:41:52 -0500, cl1motorsports wrote:
>
>>> thanks for all of your suggestions. after careful consideration i
>>> decided to change the above Accept_Visitor procedure to:
>>>
>>> procedure Accept_Vistor(V:in out Visitor_Record'Class; Node : in
>>> Parse_Tree_Node_Record'Class) is begin
>>> if Node in Equal_Op'Class then
>>> Visit(V, Equal_Op(Node));
>>> elsif Node in Number_Node'Class then
>>> Visit(V, Number_Node(Node));
>>> ...
>>> end if;
>>> end Accept_Visitor;
>>>
>>> now it only dynamically dispatches on the Visitor_Record'Class and the
>>> Node parameter is determined at compile time. I don't think i would have
>>> figured that out by myself (at least not at this point in time).
>>
>> Okay. now it works when the Visitor type, Visit() procedures and the
>> Accept_Visitor() procedure is in a separate package from the parse tree.
>> but when i try to combine the 2 into one package i get
>> an error about multiple dispatching on all of the Visit() procedures.
>> what is my scope issue with being in the same package that doesn't apply
>> to them being in 2 packages?
This is a strength of Ada. The compiler indicates a problem in your design.
Visit appears to be multiple dispatching but it is not according to your
design. You should declare it as follows:
procedure Visit
( V : in out Visitor_Record;
Node : Equal_Op'Class
) is abstract;
procedure Visit
( V : in out Visitor_Record;
Node : Number_Node'Class
) is abstract;
Now Visit dispatches in V, but does not in Node, for you do the latter
manually in Accept_Visitor.
--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de
next prev parent reply other threads:[~2003-12-23 11:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-17 18:08 how do i implement double-dispatching? cl1motorsports
2003-12-18 2:17 ` Stephen Leake
2003-12-18 9:48 ` Dmitry A. Kazakov
2003-12-18 15:13 ` Martin Krischik
2003-12-20 6:27 ` cl1motorsports
2003-12-20 9:56 ` Martin Krischik
2003-12-20 17:00 ` cl1motorsports
2003-12-21 13:39 ` Stephen Leake
2003-12-21 17:40 ` cl1motorsports
2003-12-22 22:47 ` Stephen Leake
2003-12-22 21:41 ` cl1motorsports
2003-12-22 21:47 ` cl1motorsports
2003-12-23 11:03 ` Dmitry A. Kazakov [this message]
2003-12-22 22:49 ` Stephen Leake
2003-12-22 23:04 ` cl1motorsports
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox