comp.lang.ada
 help / color / mirror / Atom feed
* Problem trying to implement generics.
@ 2001-04-11 15:04 Ayende Rahien
  2001-04-12  1:41 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 63+ messages in thread
From: Ayende Rahien @ 2001-04-11 15:04 UTC (permalink / raw)


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








^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2001-05-12 19:16 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-11 15:04 Problem trying to implement generics Ayende Rahien
2001-04-12  1:41 ` tmoran
2001-04-12 13:15   ` Ayende Rahien
2001-04-12 18:15     ` tmoran
2001-04-13 11:18       ` Ayende Rahien
2001-04-13 10:35         ` chris.danx
2001-04-13 11:54           ` Ayende Rahien
2001-04-13 11:49             ` chris.danx
2001-04-13 23:03               ` Ayende Rahien
2001-04-13 23:01                 ` Robert A Duff
2001-04-14  0:05                   ` Brian Rogoff
2001-04-14  1:12                     ` Ayende Rahien
2001-04-14  1:44                       ` Brian Rogoff
2001-04-14 14:03                         ` Dmitry A. Kazakov
2001-04-14 16:30                           ` Ayende Rahien
2001-04-14 16:28                             ` Michael Erdmann
2001-04-15  3:27                             ` James Rogers
2001-04-15 12:20                               ` Ayende Rahien
2001-04-15 14:09                               ` Dmitry A. Kazakov
2001-04-15 18:22                                 ` tmoran
2001-04-15 13:48                             ` Dmitry A. Kazakov
2001-04-15 20:44                               ` Ayende Rahien
2001-04-16 14:34                                 ` Dmitry A. Kazakov
2001-04-14  1:33                     ` Robert A Duff
2001-04-17  8:50                     ` Jean-Pierre Rosen
2001-04-17 13:20                   ` Tucker Taft
2001-04-17 16:51                     ` Ayende Rahien
2001-04-17 17:16                       ` Larry Hazel
2001-04-17 18:11                         ` Brian Rogoff
2001-04-17 19:10                           ` Marin David Condic
2001-04-17 21:08                             ` Brian Rogoff
2001-04-18 15:16                               ` Chad R. Meiners
2001-04-18 16:33                                 ` Marin David Condic
2001-04-17 21:09                             ` chris.danx
2001-04-17 21:11                             ` chris.danx
2001-04-17 21:17                             ` chris.danx
2001-05-08  5:40                             ` Lao Xiao Hai
2001-05-11  9:43                               ` John English
2001-05-12 19:16                                 ` Lao Xiao Hai
2001-04-17 19:32                           ` Larry Hazel
2001-04-17 21:03                           ` Ayende Rahien
2001-04-18 15:48                             ` Brian Rogoff
2001-04-20 12:34                               ` Georg Bauhaus
2001-04-20 12:42                                 ` Lutz Donnerhacke
2001-04-20 12:45                                 ` Lutz Donnerhacke
2001-04-20 19:48                                 ` Brian Rogoff
2001-04-20 20:36                                   ` David Starner
2001-04-20 23:02                                   ` Robert A Duff
2001-04-23  2:45                                     ` Brian Rogoff
2001-04-24  1:15                                       ` Robert A Duff
2001-04-24  2:00                                         ` Brian Rogoff
2001-04-24 15:12                                           ` Georg Bauhaus
2001-04-24 15:09                                         ` Georg Bauhaus
2001-04-24 18:36                                           ` Marius Amado Alves
2001-04-19 13:08                           ` Larry Kilgallen
     [not found]                           ` <9bi4g4$97m$1@nh.pace.Organization: LJK Software <YlSyXUaQmD+$@eisner.encompasserve.org>
2001-04-19 14:20                             ` Marin David Condic
2001-04-18  5:34                       ` Mike Silva
2001-04-18 16:55                       ` Ray Blaak
2001-04-24 16:00                       ` Tucker Taft
2001-04-12 13:57 ` Andy
2001-04-13  6:34   ` Simon Wright
2001-04-13 11:11   ` Ayende Rahien
2001-04-12 18:06 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox