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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f27fe80cb2c65260,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!k37g2000hsf.googlegroups.com!not-for-mail From: "snoopysalive@googlemail.com" Newsgroups: comp.lang.ada Subject: How to build Objects containing itself? Date: Fri, 20 Jun 2008 15:06:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4fa39546-2b0c-4579-bb26-c191c0c2f6d8@k37g2000hsf.googlegroups.com> NNTP-Posting-Host: 217.227.9.196 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1213999570 8710 127.0.0.1 (20 Jun 2008 22:06:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Jun 2008 22:06:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k37g2000hsf.googlegroups.com; posting-host=217.227.9.196; posting-account=b7G67QoAAABjwLRYV73fYo_8iKCvB0IZ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; de; rv:1.9) Gecko/2008061004 Firefox/3.0,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:791 Date: 2008-06-20T15:06:10-07:00 List-Id: 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 transitions = new HashMap(); } 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