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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,999932ecc319322a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!proxad.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: advice on package design Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1110212638.336123.298580@l41g2000cwc.googlegroups.com> Date: Mon, 7 Mar 2005 22:08:00 +0100 Message-ID: <1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net> NNTP-Posting-Date: 07 Mar 2005 22:08:00 MET NNTP-Posting-Host: e8bdc861.newsread2.arcor-online.net X-Trace: DXC=LQFmFaDQW85F:^Y;boJ3Y0Q5U85hF6f;4jW\KbG]kaM8]kI_X=5Kea6?InVSNRB8Z3WRXZ37ga[7:ncfD5BXcIX0cFZN7gUP`m< X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8830 Date: 2005-03-07T22:08:00+01:00 List-Id: On 7 Mar 2005 08:23:58 -0800, spambox@volja.net wrote: > Hello, > I've written a package for linked list operations for my personal use. > After a while I figured I'd write another package for some string > operations that I use frequently. On their own, they both work well. > Now comes the problem. > My string library uses my linked list library, which must be > instantiated -- the structure of a node must be supplied. After that, > the string library can use procedures from the linked list library. But > what about the end user? The linked list library defines a type, say > linked_list, and the string library instantiates it something like: > > type word is record ... > package string_ll is new linkedlists(word); > use string_ll; > > Ultimatelly, if some function from my strings package returns a > linked_list (as defined in the linked list package), it will be of the > type string_ll.linked_list, if we follow the above example. How could > it be available for further processing with routines from the linked > list package? > > I could "use string_ll" (exactly as in the package) in my end program, > however that's probably a poor design, since the user need not know how > something was instantiated in another package. The public part of the package is its interface. If you instantiate something there, then it is OK for all to use it. > If, on the other hand, I make another instance of linkedlist, I must > supply the same argument the string package does ("word" in the above > example), but then the resulting linked_list type would be > some_new_name.linked_list, which is not compatible with what the string > package uses (string_ll.linked_list in the example). Yes. Ada has named type equivalence. > What is the correct way of dealing with such problems? There are many different ways to deal with that. If you have 1. package Foo is type Word is ... package Baz is new Bar (Word,...); ... end Foo; then of course you can "use" Baz referencing it as Foo.Baz everywhere Foo is "with"-ed. You can even rename it: with Foo; package Baz renames Foo.Baz; 2. You can instantiate your Baz outside Foo but with the things defined in the public part of Foo: with Foo; use Foo; package Baz is new Bar (Word,...); Note that the body of Foo may still use Baz: with Baz; package body Foo is ... end Foo; Though beware that there must exits an elaboration order of the specifications and bodies Foo and Bar. 2.a. If Bar needs privates of Foo, the you can make Bar a generic child of Foo. 3. You can rename parts of contents of Baz in Foo: package Foo is type Word is ... package Baz is new Bar (Word, ...); subtype Linked_List is Baz.Linked_List; -- "renaming" of a type procedure Insert (...) renames Baz.Insert; -- renaming of a procedure ... end Foo; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de