comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Interesting containers problem.
Date: Mon, 20 Apr 2015 22:05:04 -0500
Date: 2015-04-20T22:05:04-05:00	[thread overview]
Message-ID: <mh4ep0$bdo$1@loke.gir.dk> (raw)
In-Reply-To: mh42ob$5kp$1@loke.gir.dk

I wrote:

...
> What you are talking about would help in an antique language that doesn't 
> support any overloading, but I would hope that people in this group are 
> beyond that. :-) If anything, Ada doesn't have enough overloading (too 
> much reliance on scopes, something that should have almost no bearing on 
> visibility).

It strikes me that there is an easy way to use the containers for a purely 
scoped language without any overloading. There's some overhead with scope 
exit (but that seems necessary in any case). The basic idea is to use 
cursors to link nested items together, and have the map point at the 
currently visible item:

   package Symbol_Tree is new Ada.Containers.Indefinite_Multiway_Trees
       (Element_Type => Symbol_Root'Class);

   package Identifier_Map is new Ada.Containers.Indefinite_Hashed_Map
        (Element_Type => Symbol_Tree.Cursor,
         Key_Type => String, -- Probably really a UTF8_String,
         Hash => ..., Equivalent_Keys => ...);

For this to work, each item in Symbol_Root'Class needs a 
Previous_Declaration component that also has type Symbol_Tree.Cursor. That 
points at the previous item (if any) that was visible before the current 
one.

A new declaration updates the map to point at itself in the symbol table, 
but not before squirreling the previous item (if any) into 
Previous_Declaration. When a declaration goes out of scope, the map has to 
be updated to put again at the Previous_Declaration (if any). This is 
essentially the same way one would write such a symbol table with access 
types.

Such a pure scheme doesn't work for module visibility (i.e. use clauses in 
Ada), because there can be multiple items visible at once that way. But I 
suppose that a very simple language might make it work (no overloading, no 
modules or at least only dot notation for modules). Janus/Ada worked that 
way initially (when doing the Pascal subset), but that didn't last long for 
obvious reasons.

                                   Randy.



  reply	other threads:[~2015-04-21  3:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-17 13:42 Interesting containers problem Shark8
2015-04-17 19:12 ` Peter Chapin
2015-04-17 20:45   ` Randy Brukardt
2015-04-17 21:06     ` Dmitry A. Kazakov
2015-04-18 17:21     ` Shark8
2015-04-19 17:10       ` brbarkstrom
2015-04-20 23:39       ` Randy Brukardt
2015-04-21  3:05         ` Randy Brukardt [this message]
2015-04-21  8:06         ` Dmitry A. Kazakov
2015-04-21  8:28           ` J-P. Rosen
2015-04-21  8:45             ` Dmitry A. Kazakov
replies disabled

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