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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Interesting containers problem. Date: Mon, 20 Apr 2015 22:05:04 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <8def4a86-5835-4368-b414-63e12f1074e8@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1429585505 11704 24.196.82.226 (21 Apr 2015 03:05:05 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 21 Apr 2015 03:05:05 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Response Xref: news.eternal-september.org comp.lang.ada:25560 Date: 2015-04-20T22:05:04-05:00 List-Id: 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.