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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1dd28d5040ded1f8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-15 06:40:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!pec-138-6.tnt8.hh2.uunet.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Announce: Grace project site operational Date: Wed, 15 May 2002 15:41:28 +0200 Message-ID: References: NNTP-Posting-Host: pec-138-6.tnt8.hh2.uunet.de (149.225.138.6) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1021470000 22169581 149.225.138.6 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:24093 Date: 2002-05-15T15:41:28+02:00 List-Id: On Wed, 15 May 2002 13:32:48 +0200 (MET DST), "Grein, Christoph" wrote: >From: "Dmitry A.Kazakov" >> Consider: >> >> type Graph_Node is private; >> No_Node : constant Graph_Node; -- Deferred, but visible >> function Get_Next_Child >> (Parent : Graph_Node; Child : Graph_Node := No_Node) >> return Graph_Node; >> >> Here I exposed No_Node, which then can be abused like: >> >> Get_Next_Child (No_Node); >> >> A solution could be some sort of incomplete declaration for >> subprograms: >> >> type Graph_Node is private; >> function Get_Next_Child >> (Parent : Graph_Node; Child : Graph_Node := <>) >> return Graph_Node; > >Your caller has to have some variable Current_Parent, which might have the value >No_Node, e.g. when it is undefined (private types should be defaulted to >something like this so that they always have a value even when never assigned a >value). Fortunately, with Ada 95 we have a way to ensure that all variables get initialized: type Graph_Node (<>) is private; -- Prevents uninitialized variables >So you must make sure in any case that the actual for Parent is different from >No_Node, so the abusive > > Get_Next_Child (No_Node); > >is caught in any case. That's for sure, because Graph_Node will probably be a record containing an access type, dereferenced and thus checked at run-time. But this is no matter, because no run-time checks may supersede compile-time ones. Another story is that with a more advanced ADT there might be a way to easily create a supertype Graph_Node_With_No_Node and then leave the work to the compiler. But this is a long way to go. >There are cases where > > .---------------------------------------. > | Information Hiding Considered Harmful | > `---------------------------------------' Egh, where am I? Is this comp.lang.ada? (:-)) --- Regards, Dmitry Kazakov www.dmitry-kazakov.de