From: "Ayende Rahien" <Dont@spam.me>
Subject: Re: Problem trying to implement generics.
Date: Sat, 14 Apr 2001 01:03:42 +0200
Date: 2001-04-14T01:03:42+02:00 [thread overview]
Message-ID: <9b7tce$laf$2@taliesin.netcom.net.uk> (raw)
In-Reply-To: 0JBB6.10484$FD1.1197250@news6-win.server.ntlworld.com
"chris.danx" <chris.danx@ntlworld.com> wrote in message
news:0JBB6.10484$FD1.1197250@news6-win.server.ntlworld.com...
>
> > >
> > > > private
> > > > type Binary_Tree is new Ada.Finalization.controlled with record
> > > > root: Node_access := null;
> > > > end record;
> > >
> > > the error comes because
> > >
> > > > package body binTree is
> > > [snip]
> > > > procedure insert(insert_this : in data_type; Sort : in sort_by) is
> > > > New_node : Node_Access := new node;
> > > > current : Node_access := root; -- This is the line it compline
> about!!
> > >
> > > you've forgot to that Root is in Binary_Tree.
> >
> > Okay, so how do I fix it? And what is wrong, anyway?
>
> What you do is pass in a Binary_Tree type with appropriate mode. In C++
you
> have objects that store the methods with the data in the class. This
means
> you don't need to refer to the object name and you can just use "root".
In
> Ada methods are simply procedures and functions that work with objects
> passed in.
>
> In C++ you'd have
>
> BinTree.insert(insert_this, sort);
>
> but in Ada
>
> insert(BinTree, insert_this, sort);
>
> You use the methods with the object type. So you'd have to pass in an
item
> of type Binary_Tree with appropriate mode and use the "root" field in
this.
>
> e.g.
> procedure insert (BT : in out Binary_Tree;
> insert_this : ...
> sort : ...) is
> New_node : Node_Access := new node;
> current : Node_access := BT.root; -- This is what you need to do!
> begin
> .........................
> .........................
> end insert;
>
> If your interested i have a generic doubly linked list ADT written in Ada.
> It's part of the Heather modules i'm writing. I know it isn't based on
> tagged types(Ada objects), but it does show how to build an ADT. Your
> implementation of Binary_Tree is "Limited controlled" which means it's a
> tagged type, but i haven't added this property to it yet. I may soon, or
at
> least make it controlled. It really doesn't matter that much since it's
> just an example.
>
> I will put it up on my site if you let me know you want it.
Maybe later, right now I want to implement those myself, it's a good
practice, and make for excellent tools afterward.
> > > I have a question. From your code it doesn't look like an ADT. Is
this
> > > what you intended? I can't remember the term for what this looks
like,
> > but
> > > I think it's to do with storing the Tree as a global variable in the
> > package
> > > not as an ADT.
> >
> > Okay, major cocept problem here.
> > I'm coming here with C/C++ background, and I understand that Ada has a
> > different OO paradigm.
> > I assumed that for each Binary_Tree spesific type that I create, there
> would
> > be its own Root.
> > I mean:
> > package Int_BinTree is new Binary_Tree(data_type=>
> > Integer,Sort_by=>Integer);
> >
> > Bin_Tree_First, Bin_Tree_Second : Int_BinTree;
> >
> > Does Bin_Tree_First.Root = Bin_Tree_Second.Root ?
> >
> >
> > > If you want an ADT you need to pass in a Binary_Tree type as
necessary.
> I
> > > didn't see it any where in your code so i'm assuming it's based on a
> > global
> > > variable.
> >
> > I think that you are talking about ADO vs ADT , right?
> > generic abstract data type & generic abstract data object
>
> Yes, that's it. ADO -- i must remember that!
>
>
> > > There's nothing wrong doing it this way!
> >
> > Then why doesn't it compile?
>
> It doesn't compile because Ada's OO is based on extensible records. You
> have to pass the record in even though it's an Object. In C++ the object
> methods are held inside the class which means they have access to the
> variables inside. This is not the same as Ada.
>
> Maybe, this is a better explanation, it's just like C records. Just pass
in
> the record and use it as you wish. Remember to get the correct mode, and
> use the record like you would in C.
>
> There's more to Ada's OO but you don't need it for your Binary_Tree and
I'm
> still learning about it myself.
Thanks, that helped, it now compiles.
BTW, is there any reason why I can't use out parameter with a function?
next prev parent reply other threads:[~2001-04-13 23:03 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox