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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.104.68 with SMTP id gc4mr1199512obb.40.1406133630845; Wed, 23 Jul 2014 09:40:30 -0700 (PDT) X-Received: by 10.140.94.38 with SMTP id f35mr37429qge.9.1406133630820; Wed, 23 Jul 2014 09:40:30 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!nntp.giganews.com!h18no6196485igc.0!news-out.google.com!j6ni12934qas.0!nntp.google.com!v10no2087371qac.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 23 Jul 2014 09:40:30 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.27.77; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 NNTP-Posting-Host: 158.110.27.77 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6c344059-08de-4212-be81-c90889410b5b@googlegroups.com> Subject: Re: Parent/child dependencies and internal library units From: mockturtle Injection-Date: Wed, 23 Jul 2014 16:40:30 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:187809 Date: 2014-07-23T09:40:30-07:00 List-Id: On Wednesday, July 23, 2014 6:20:27 PM UTC+2, Victor Porton wrote: > I noticed that child units depend on their parents. >=20 > As such making parent dependent on a child makes a dependency loop. >=20 > Before noting this feature of Ada language, I thought parent units could = be=20 > implemented based on their child units, but that does not work, because= =20 > making parents dependent on children is a circular dependency. >=20 > So, my question: >=20 > What is a good way to create "internal" or "implementation" units for a= =20 > unit? Should I create a *.Internal.* hierarchy of packages? >=20 My personal solution to this kind of problem is to make the implementation = units "private sibling" of the main unit. Also note that the body of the p= arent (if I am not mistaken) can use a child. Let me do an example (maybe not a perfect one, I am inventing it "on the sp= ot"). Suppose you have a program (call it "calculator") that uses some kin= d of expressions. In particular, you want to parse expressions and evaluat= e the result of parsing. Say the parser needs a "symbol table" package to = keep track of variables and stuff, and a "scanner" to split the input into = tokens. So, you could have a tree of packages like package Calculator is ... =20 -- The "root" of the whole program end Calculator; package Calculator.Expressions is=20 -- The "root" of the part that handles expressions -- Depending on your code, it could be empty=20 -- and just provide a root for its subtree. It is -- more likely that it will have a "Expression" type -- that represents the internal version of an expression end Calculator.Expressions; package Calculator.Expressions.Parsing is=20 -- This package exports resources (types, procedures...) -- for parsing expressions. end Calculator.Expressions.Parsing; private package Calculator.Expressions.Scanner is=20 -- Implements a scanner. Note the "private" keyword -- None outside the Calculator.Expressions subtree can use this end Calculator.Expressions.Scanner; private package Calculator.Expressions.Symbol_Tables is=20 -- Implements the symbol table end Calculator.Expressions.Symbol_Tables;