From: mockturtle <framefritti@gmail.com>
Subject: Re: Parent/child dependencies and internal library units
Date: Wed, 23 Jul 2014 09:40:30 -0700 (PDT)
Date: 2014-07-23T09:40:30-07:00 [thread overview]
Message-ID: <6c344059-08de-4212-be81-c90889410b5b@googlegroups.com> (raw)
In-Reply-To: <lqoncd$ue7$1@speranza.aioe.org>
On Wednesday, July 23, 2014 6:20:27 PM UTC+2, Victor Porton wrote:
> I noticed that child units depend on their parents.
>
> As such making parent dependent on a child makes a dependency loop.
>
> Before noting this feature of Ada language, I thought parent units could be
> implemented based on their child units, but that does not work, because
> making parents dependent on children is a circular dependency.
>
> So, my question:
>
> What is a good way to create "internal" or "implementation" units for a
> unit? Should I create a *.Internal.* hierarchy of packages?
>
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 parent (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 spot"). Suppose you have a program (call it "calculator") that uses some kind of expressions. In particular, you want to parse expressions and evaluate 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 ...
-- The "root" of the whole program
end Calculator;
package Calculator.Expressions is
-- The "root" of the part that handles expressions
-- Depending on your code, it could be empty
-- 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
-- This package exports resources (types, procedures...)
-- for parsing expressions.
end Calculator.Expressions.Parsing;
private package Calculator.Expressions.Scanner is
-- 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
-- Implements the symbol table
end Calculator.Expressions.Symbol_Tables;
next prev parent reply other threads:[~2014-07-23 16:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
2014-07-23 16:40 ` mockturtle [this message]
2014-07-23 16:47 ` Simon Wright
2014-07-23 16:48 ` Adam Beneschan
2014-07-23 18:37 ` Stefan.Lucks
2014-07-23 21:31 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox