comp.lang.ada
 help / color / mirror / Atom feed
* Universal type
@ 2007-08-03 18:28 shaunpatterson
  2007-08-03 18:31 ` shaunpatterson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: shaunpatterson @ 2007-08-03 18:28 UTC (permalink / raw)


I'm looking to store different kinds of objects into a vector, queue,
etc

In Java, everything is derived from Object.  Is there something
similar
in Ada?  I'd like to be able to store Integers, booleans, etc, as
well
as custom defined objects.

I have implemented a simple linked list ung generics:

generic
        type ElementType is private;

Package GenericList is

type Node is Record
                Info : ElementType;
                Link : Position;
        end Record;




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

* Re: Universal type
  2007-08-03 18:28 Universal type shaunpatterson
@ 2007-08-03 18:31 ` shaunpatterson
  2007-08-03 19:10   ` Dmitry A. Kazakov
  2007-08-03 23:03 ` Georg Bauhaus
  2007-08-05 13:46 ` Martin Krischik
  2 siblings, 1 reply; 9+ messages in thread
From: shaunpatterson @ 2007-08-03 18:31 UTC (permalink / raw)


Sorry, hit Tab+Space and sent the message prematurely...


Anyway, this generic list allows me to store one type of
data. Is there a way of taking this concept and store
many different types?

Thanks
--
Shaun




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

* Re: Universal type
  2007-08-03 18:31 ` shaunpatterson
@ 2007-08-03 19:10   ` Dmitry A. Kazakov
  2007-08-03 20:35     ` Maciej Sobczak
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry A. Kazakov @ 2007-08-03 19:10 UTC (permalink / raw)


On Fri, 03 Aug 2007 11:31:00 -0700, shaunpatterson@gmail.com wrote:

> Anyway, this generic list allows me to store one type of
> data. Is there a way of taking this concept and store
> many different types?

What will you do with that list? The items of will have no single method in
common, except some attributes like X'Address. It would be a quite useless
thing.

But, yes, technically you can. Root_Stream_Type and Root_Storage_Pool can
hold anything. It is possible to implement a linked list with objects of
any type in it. I don't what to go into details, let us just assume we
already have one. So we have the function Next (Node : ...) return
Some_Ptr; And? How are you going to determine what it points to?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Universal type
  2007-08-03 19:10   ` Dmitry A. Kazakov
@ 2007-08-03 20:35     ` Maciej Sobczak
  2007-08-03 21:54       ` shaunpatterson
  2007-08-04  7:21       ` Dmitry A. Kazakov
  0 siblings, 2 replies; 9+ messages in thread
From: Maciej Sobczak @ 2007-08-03 20:35 UTC (permalink / raw)


On 3 Sie, 21:10, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> What will you do with that list?

The "C-way-of-thinking" is regularly criticized here, but
interestingly, the "Java-way-of-thinkng" doesn't seem to be much
better... ;-)

My answer to the above question: Java people added generics and (more
or less) typesafe collections for a reason - their initial idea of
storing anything in a single collection didn't please even themselves.
This should be a hint that maybe Ada (and C++ for that matter) got it
right already, so why trying to work around it?

--
Maciej Sobczak
http://www.msobczak.com/




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

* Re: Universal type
  2007-08-03 20:35     ` Maciej Sobczak
@ 2007-08-03 21:54       ` shaunpatterson
  2007-08-04  1:10         ` Jeffrey R. Carter
  2007-08-04  7:21       ` Dmitry A. Kazakov
  1 sibling, 1 reply; 9+ messages in thread
From: shaunpatterson @ 2007-08-03 21:54 UTC (permalink / raw)


Well... interesting enough, I realize I don't
need it. Without going into it much, we'll just
leave it at that.

And speaking of Java/C++/Ada. I have been working on a
messaging system that has a direct analog in a Java
front-end client to the C++/Ada backend.  All the code
is essentially the same for every language.

I coded the Java system and the C++ backend system initially.
I have finally fully converted the C++ backend to Ada.
Looking back on the process, surprisingly Ada WOULD have
been the easiest if I had actually known Ada...

Thanks for the advice these past few weeks

--
Shaun




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

* Re: Universal type
  2007-08-03 18:28 Universal type shaunpatterson
  2007-08-03 18:31 ` shaunpatterson
@ 2007-08-03 23:03 ` Georg Bauhaus
  2007-08-05 13:46 ` Martin Krischik
  2 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2007-08-03 23:03 UTC (permalink / raw)


On Fri, 2007-08-03 at 11:28 -0700, shaunpatterson@gmail.com wrote:
> I'm looking to store different kinds of objects into a vector, queue,
> etc
> 
> In Java, everything is derived from Object.  Is there something
> similar
> in Ada?  I'd like to be able to store Integers, booleans, etc, as
> well
> as custom defined objects.

While I agree with Dmitry and Maciej (that there must be
a reason that Java now has generic containers), if you still
wanted containers to hold objects of types derived from Object,
you could do just the same thing that Java does, and define
an all-emcompassing parent type.

In fact, two Ada compilers do exactly this for running Ada
programs in a JVM. The "Object" type in the RTL of one of
these compilers is

    type Object is tagged limited null record;
    type Object_Ptr is access all Object'Class;

    function hashCode(Obj : access Object) return Integer;

    -- see java.lang.Object_ops package for rest of
    -- "Object" abstraction

Package Object_ops starts

    function getClass(Obj : access Object'Class) return Class_Ptr;

    function toString(Obj : access Object'Class) return String_Ptr;
    function "="(Left: Object'Class; Right : Object'Class) return
Boolean;

    procedure notify(Obj : access Object'Class);

    ...

Since Java objects stored in containers are really references to
heap allocated objects, you would be doing the same using
access values in Ada.





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

* Re: Universal type
  2007-08-03 21:54       ` shaunpatterson
@ 2007-08-04  1:10         ` Jeffrey R. Carter
  0 siblings, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2007-08-04  1:10 UTC (permalink / raw)


shaunpatterson@gmail.com wrote:
> 
> I coded the Java system and the C++ backend system initially.
> I have finally fully converted the C++ backend to Ada.
> Looking back on the process, surprisingly Ada WOULD have
> been the easiest if I had actually known Ada...

Not surprising at all to people familiar with Ada.

-- 
Jeff Carter
"Why, the Mayflower was full of Fireflies, and a few
horseflies, too. The Fireflies were on the upper deck,
and the horseflies were on the Fireflies."
Duck Soup
95



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

* Re: Universal type
  2007-08-03 20:35     ` Maciej Sobczak
  2007-08-03 21:54       ` shaunpatterson
@ 2007-08-04  7:21       ` Dmitry A. Kazakov
  1 sibling, 0 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2007-08-04  7:21 UTC (permalink / raw)


On Fri, 03 Aug 2007 13:35:05 -0700, Maciej Sobczak wrote:

> My answer to the above question: Java people added generics and (more
> or less) typesafe collections for a reason - their initial idea of
> storing anything in a single collection didn't please even themselves.

Java people added generics because it was fashionable at that time.
Generics or not, the problem stays. The set of types in the class of the
list items does not have common methods.

Here class = the set of all types an item of *the* list may have. Note that
generics change here absolutely nothing to better:

generic
   type Item is ...
package Generic_Container is

Each instance of this package has exactly one type of items => all items of
a list have *same* type.

Generics provide one polymorphic implementation for lists of many types,
but that does not make lists themselves polymorphic. Don't mix a macro and
its expansions. (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Universal type
  2007-08-03 18:28 Universal type shaunpatterson
  2007-08-03 18:31 ` shaunpatterson
  2007-08-03 23:03 ` Georg Bauhaus
@ 2007-08-05 13:46 ` Martin Krischik
  2 siblings, 0 replies; 9+ messages in thread
From: Martin Krischik @ 2007-08-05 13:46 UTC (permalink / raw)


 shaunpatterson@gmail.com wrote:

> I'm looking to store different kinds of objects into a vector, queue,
> etc
> 
> In Java, everything is derived from Object.  Is there something
> similar
> in Ada? 

Yes: System.Address. Ok, that's a joke - but with a true core: Java too does
not store instances of Object - it too stores pointers of  instances of
Object. Ok, the pointers are hidden from sight - but so are the pointers
used in Unlimited_Vector.

And also, you can't store "int" in a a Java Vector - you can only
store "Integer". And behind the scenes it is again a "pointer to Integer".
Which is exactly what Unlimited_Vector does.

So again Yes: If you are prepared to accept the same restrictions which are
valid in Java. 

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

end of thread, other threads:[~2007-08-05 13:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-03 18:28 Universal type shaunpatterson
2007-08-03 18:31 ` shaunpatterson
2007-08-03 19:10   ` Dmitry A. Kazakov
2007-08-03 20:35     ` Maciej Sobczak
2007-08-03 21:54       ` shaunpatterson
2007-08-04  1:10         ` Jeffrey R. Carter
2007-08-04  7:21       ` Dmitry A. Kazakov
2007-08-03 23:03 ` Georg Bauhaus
2007-08-05 13:46 ` Martin Krischik

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