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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,87077e61d6b3095b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-23 02:57:15 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!dialin-145-254-041-053.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: how do i implement double-dispatching? Date: Tue, 23 Dec 2003 12:03:32 +0100 Organization: At home Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-041-053.arcor-ip.net (145.254.41.53) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1072177034 11156050 145.254.41.53 ([77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:3745 Date: 2003-12-23T12:03:32+01:00 List-Id: 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