* Parent/child dependencies and internal library units
@ 2014-07-23 16:20 Victor Porton
2014-07-23 16:40 ` mockturtle
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Victor Porton @ 2014-07-23 16:20 UTC (permalink / raw)
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?
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Parent/child dependencies and internal library units
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
@ 2014-07-23 16:40 ` mockturtle
2014-07-23 16:47 ` Simon Wright
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mockturtle @ 2014-07-23 16:40 UTC (permalink / raw)
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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Parent/child dependencies and internal library units
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
2014-07-23 16:40 ` mockturtle
@ 2014-07-23 16:47 ` Simon Wright
2014-07-23 16:48 ` Adam Beneschan
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Simon Wright @ 2014-07-23 16:47 UTC (permalink / raw)
Victor Porton <porton@narod.ru> writes:
> 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?
I dare say there are uses which could make this not work (possibly
involving initialisation of objects in specs via function calls, leading
to access-before-elaboration) but you can make a parent body depend on a
child spec.
If the implementation is meant to be hidden from users outside the
parent, consider using private child packages.
package Hierarchy is
procedure Tell;
end Hierarchy;
private package Hierarchy.Internal is
procedure Tell;
end Hierarchy.Internal;
with Ada.Text_IO;
package body Hierarchy.Internal is
procedure Tell is
begin
Ada.Text_IO.Put_Line ("Hierarchy.Internal");
end Tell;
end Hierarchy.Internal;
with Ada.Text_IO;
with Hierarchy.Internal;
package body Hierarchy is
procedure Tell is
begin
Ada.Text_IO.Put_Line ("Hierarchy");
Internal.Tell;
end Tell;
end Hierarchy;
procedure Hierarchy.Main is
begin
Tell; -- this is Hierarchy.Tell
end Hierarchy.Main;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Parent/child dependencies and internal library units
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
2014-07-23 16:40 ` mockturtle
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
4 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2014-07-23 16:48 UTC (permalink / raw)
On Wednesday, July 23, 2014 9:20:27 AM UTC-7, 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.
When you talk about parent units being "implemented" based on their child units, are you talking about the *body* of a parent unit (which is where "implementation" normally lives)? There's no problem with making the body of a parent unit depend on a child unit. A child unit depends on its parent's *specification* but not on its body, so having the body of the parent depend on the child does not create a loop.
It might help to give a short example of what you want to write (even if it's not legal Ada because of a circular dependency). As it is, I'm not clear on what you're trying to do.
-- Adam
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Parent/child dependencies and internal library units
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
` (2 preceding siblings ...)
2014-07-23 16:48 ` Adam Beneschan
@ 2014-07-23 18:37 ` Stefan.Lucks
2014-07-23 21:31 ` Robert A Duff
4 siblings, 0 replies; 6+ messages in thread
From: Stefan.Lucks @ 2014-07-23 18:37 UTC (permalink / raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 618 bytes --]
On Wed, 23 Jul 2014, Victor Porton wrote:
> What is a good way to create "internal" or "implementation" units for a
> unit? Should I create a *.Internal.* hierarchy of packages?
I am not sure if it is a good way, but I usually define a project-specific
"super package", often just an empty package. Then I define both internal
and external packages as children of the super package.
------ I love the taste of Cryptanalysis in the morning! ------
<http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
--Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Parent/child dependencies and internal library units
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
` (3 preceding siblings ...)
2014-07-23 18:37 ` Stefan.Lucks
@ 2014-07-23 21:31 ` Robert A Duff
4 siblings, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2014-07-23 21:31 UTC (permalink / raw)
Victor Porton <porton@narod.ru> writes:
> 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?
Cyclic dependences are allowed if you say "limited with".
And as others have pointed out, a package body can "with"
its children.
- Bob
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-07-23 21:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-23 16:20 Parent/child dependencies and internal library units Victor Porton
2014-07-23 16:40 ` mockturtle
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox