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,ad988eb0a9545c86,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-11 07:08:05 PST Path: supernews.google.com!sn-xit-03!supernews.com!freenix!fr.clara.net!heighliner.fr.clara.net!RENT.THIS.SPACE.FOR.ADVERTISING!diablo.netcom.net.uk!netcom.net.uk!not-for-mail From: "Ayende Rahien" Newsgroups: comp.lang.ada Subject: Problem trying to implement generics. Date: Wed, 11 Apr 2001 17:04:22 +0200 Organization: (Posted via) GTS Netcom - Public USENET Service http://pubnews.netcom.net.uk Sender: ayende@softhome.net Message-ID: <9b1oe1$i4m$1@taliesin.netcom.net.uk> NNTP-Posting-Host: diup-181-145.inter.net.il X-Trace: taliesin.netcom.net.uk 986998018 18582 213.8.181.145 (11 Apr 2001 14:06:58 GMT) X-Complaints-To: abuse@corp.netcom.net.uk NNTP-Posting-Date: Wed, 11 Apr 2001 14:06:58 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.60.2296.0000 X-MimeOLE: Produced By Microsoft MimeOLE V5.60.2296.0000 Xref: supernews.google.com comp.lang.ada:6757 Date: 2001-04-11T17:04:22+02:00 List-Id: I've just started to learn Ada, and I've some problem solving some problems. Here is the spec I'm trying to compile: with Ada.Finalization; generic type data_type is private; type Sort_by is private; package Binary_Trees is type binary_Tree is new Ada.Finalization.controlled with private; type node is private; type node_access is access all Node; type data_access is access all Data_type; procedure insert(insert_this : in data_type; Sort : in sort_by); --Insert into the binary tree, sort according to sort. function Delete(Delete_this: in Sort_by; Index : in natural := 1) return boolean; -- Delete a node from the tree, return true if succeeded, return false if -- the node does not exist. function Get(Search_For: in sort_by; index : in natural := 1) return data_access; -- Search for nodes with duplicate sort_by variable. It find the first -- node with the sort_by equal to the given one, and then continue to check for Index -- number of duplicated. It return null if it there isn't a suitable node in the -- correct index. private type Binary_Tree is new Ada.Finalization.controlled with record root: Node_access := null; end record; type node is record Data : Data_type; Sorted_by: Sort_by; Parent, Left, right : Node_access; end record; procedure Adjust(Object : in out Binary_Tree ); procedure Finalize(Object : in out Binary_Tree ); end Binary_Trees; I trying to put the defination of Node in the body, but it results in compilation error, is there some way to put the defination in the body? Or does it matter naught, because it's on the private part of the package? Since it's a binary tree, I've to have > working on all types that sort_by work on. How do I force it? At the moment, I've three compilation errors when I'm trying to use > on sort_by data. Here is the error: bintree.adb: Error: line 43 col 25 LRM:8.4(1), Binary operator ">" between Sort_by and Sort_by not directly visible, use clause or conversion might be needed This line also result in an error, and I don't know why: procedure insert(insert_this : in data_type; Sort : in sort_by) is Here is the error this line produce: bintree.adb: Error: line 107 col 12 LRM:3.11.1(7), subprogram body is a homograph of another subprogram which does not require a completion, continuing I also have this function: function Get(Search_For: in sort_by; index : in natural := 1) return data_access is result : node_access := find(search_for,index); begin if result = null then return null; else return result.data'access; end if; end get; find return a node_access, get translate it to data_access, I tried using 'access tag to make it return data_access, but it didn't qute work. Here is the error: bintree.adb: Error: line 150 col 18 LRM:3.10.2(23&31), The prefix to 'ACCESS must be either an aliased view of an object or denote a subprogram with a non-intrinsic calling convention, Continuing Also I've a trouble using Root variable in a function that is undefied in the spec (Find function). I suppose I could put it in the private part, but can it be avoided? Here is the error I got: bintree.adb: Error: line 8 col 28 LRM:4.1(3), Direct name, root, is not visible, Ignoring future references Thanks in advance, Ayende Rahien