comp.lang.ada
 help / color / mirror / Atom feed
From: "snoopysalive@googlemail.com" <snoopysalive@googlemail.com>
Subject: How to build Objects containing itself?
Date: Fri, 20 Jun 2008 15:06:10 -0700 (PDT)
Date: 2008-06-20T15:06:10-07:00	[thread overview]
Message-ID: <4fa39546-2b0c-4579-bb26-c191c0c2f6d8@k37g2000hsf.googlegroups.com> (raw)

Hi!

So, here's my next question about object orientation in Ada.

In languages like Ruby, C++ or Java, the following construct is
possible (here in Java):

class State {
    HashMap<char, State> transitions = new HashMap<char, State>();
}

Perhaps you're wondering, what this code is meant to be. Some time ago
I programmed a stack-structure simulating a trie as part of a
incremental search-algorithm. The idea was to have a state-object
containing a mapping of characters pointing to state-objects again.
So, the result is a data-structure containing instances of its own
data type again.

As object orientation is a bit different in Ada, the previous code
example would be something like this in Ada:

package State is

    type State is tagged
        record
            Transitions : Transition_Maps.Map;
        end record;

    package Transition_Maps is new Ada.Containers.Ordered_Maps
        (Key_Type => Character,
         Element_Type => State,
         "<" => "<",
         "=" => "=");
    use Transition_Maps;

end State;


As you can see, we have a "What had been there first? The hen or the
egg?"-problem: The State-record requires an instance of
Transition_Maps.Map which is declared after the State-record's
definition. But because Transition_Maps.Map needs a State as
Element_Type changing the order ends in the same problem.

So, has anybody an idea, how to solve this paradox?

Thanks,
Matthias



             reply	other threads:[~2008-06-20 22:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-20 22:06 snoopysalive [this message]
2008-06-20 22:42 ` How to build Objects containing itself? george.priv
2008-06-21  5:57   ` Ivan Levashew
replies disabled

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