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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,887bac6875d2db34 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!c23g2000hsa.googlegroups.com!not-for-mail From: Gene Newsgroups: comp.lang.ada Subject: Re: Access idiom Date: Mon, 21 Jan 2008 19:56:54 -0800 (PST) Organization: http://groups.google.com Message-ID: <26cde0d5-2c5e-4316-aad7-95fd7269646a@c23g2000hsa.googlegroups.com> References: <6j5lj.309998$Fc.80333@attbi_s21> NNTP-Posting-Host: 70.101.174.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1200974214 20610 127.0.0.1 (22 Jan 2008 03:56:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 22 Jan 2008 03:56:54 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c23g2000hsa.googlegroups.com; posting-host=70.101.174.178; posting-account=-BkjswoAAACC3NU8b6V8c50JQ2JBOs04 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19522 Date: 2008-01-21T19:56:54-08:00 List-Id: On Jan 21, 1:15=A0pm, "Jeffrey R. Carter" wrote: > Gene wrote: > > > I'm at an impasse developing a graph data structure. =A0There are many > > node types derived from a "most general" one. =A0Most of the node types > > contain fields that are classwide access to child nodes. =A0Various > > primitive procedures operate on nodes, dispatching on unnamed node > > access types. =A0In many cases, the operations return such an access > > child value. =A0Other "identity" ops just return the dispatching > > parameter as classwide access. > > There should be no need for public access types or values in such a data > structure. Hiding them should make the package easier to use, easier to > implement, and safer. First, I think the collective wisdom has put me straight. Thanks. Another, more succinct explanation... The graph has many node types, all with common ancestor. Edges are pointers--named or anonymous access Node_Type'Class; don't care which. Required is a primitive "transform" procedure that dispatches on node type and must return a pointer to an _arbitrary node type_ (i.e. again of type access Node_Type'Class). Frequently the transform should just return its parameter without modification. Using primitive functions (which would enable return of anonymous access Node_Type'Class) is not good due to need for multiple return values. Jeff, in view of all the above, a named "access all Node_Type'Class" type seems necessary for the return values. I failed earlier because the out parameter wouldn't convert automatically from named to unnamed access, and I didn't realize type conversion would work on L-values. Further comments very welcome if there is a better way. Again, thanks. This compiles and dispatches as expected: ---- hoo.ads package Hoo is type Node_Type is abstract tagged null record; type Node_Ptr_Type is access all Node_Type'Class; procedure XForm(P : access Node_Type; Rtn : out Node_Ptr_Type) is abstract; type Binary_Type is new Node_Type with record Left, Right : access Node_Type'Class; end record; overriding procedure XForm(P : access Binary_Type; Rtn : out Node_Ptr_Type); end Hoo; ---- hoo.adb package body Hoo is overriding procedure XForm (P : access Binary_Type; Rtn : out Node_Ptr_Type) is begin Rtn :=3D Node_Ptr_Type(P); end XForm; end Hoo; ---- foo.adb procedure Foo is P : access Binary_Type; begin P :=3D new Binary_Type; Xform(P.Left, Node_Ptr_Type(P.Left)); end Foo;