Prev: Ada 2012: An Oops in the new Ada amendments ? (in 10.1.2 ContextClauses - With Clauses)
Next: Ada 2012: An Oops in the new Ada amendments ? (in 10.1.2 Context Clauses - With Clauses)
From: Dmitry A. Kazakov on 13 Aug 2010 04:40 On Fri, 13 Aug 2010 09:42:15 +0200, Georg Bauhaus wrote: > On 8/13/10 8:27 AM, Dmitry A. Kazakov wrote: > >> Another rule of thumb (I don't know if this is going to be fixed in Ada >> 2012), is that a child should always rename formal generic arguments in its >> specifications. Under certain circumstances, usually in children, they >> might become unavailable. I mean this: > > Would you mind showing an example of a name that is needed > but unavailable? >> generic >> with package P is new Generic_P (<>); >> package Generic_S is >> package P_Of renames P; -- You will need this! Do you mean the use case or the offending code? I cannot say for the latter because I have no idea when it happens and if the code is legal [*]. The simplest possible use case is the diamond diagram of generic packages [**]: A / \ B C \ / D In the specification of D you have to constrain B and C to the same A. For this you will need to refer the parameters of B and C: generic package A is end A; generic with package AA is new A (<>); package B is end B; generic with package AA is new A (<>); package C is end C; generic with package BB is new B (<>); with package CC is new C (BB.AA); -- Somewhere, somehow this ceases to work package D is end D; Note that Simon's problem is the same use case (just one shoulder of the diagram) but of different shape [*]: generic package A is end A; generic package A.B is end A.B; generic package A.C is end A.C; with A.B, A.C; generic with package AB is new A.B (my own A); -- No way! with package AC is new A.C (my own A); -- No way! package A.D is end D; ----------- * Generics is a mess, remember? ** We were told how dreadful the diamond is, so bad that Ada may not allow to have MI, but for sacred generics anything is perfectly OK! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Yannick Duchêne (Hibou57) on 13 Aug 2010 09:31 Le Fri, 13 Aug 2010 08:27:52 +0200, Dmitry A. Kazakov <mailbox(a)dmitry-kazakov.de> a écrit: >> In other places I've tacked _G on the end of the 'obvious' name: >> >> generic >> package ColdFrame.Events_G.Standard_G.Callback_Manager_G is >> >> and I saw someone else (Ludovic?) doing the same here recently. > > I used plural suffix 's' before, but it Generic is clearer and it seems > like a semi-standard now. You mean the _G suffis became a somewhat de-facto standard ? > Yes, especially because of two "Extensions". I had immense problems with > names. Look at this: > > http://www.dmitry-kazakov.de/ada/fuzzy_packages.gif Will have to look at it again, as I did not really understand this one. > Another rule of thumb (I don't know if this is going to be fixed in Ada > 2012), is that a child should always rename formal generic arguments in > its > specifications. Under certain circumstances, usually in children, they > might become unavailable. I mean this: > > generic > with package P is new Generic_P (<>); > package Generic_S is > package P_Of renames P; -- You will need this! > > Sometimes you need to "rename" formal types as well: > > generic > type Foo is ... > package Generic_S is > subtype Foo_Of is Foo; -- What a mess! We already talked about these cases. Do you remember the thread's title ? (I would like to get it back to read it again). -- There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.
From: Yannick Duchêne (Hibou57) on 13 Aug 2010 09:36 Le Fri, 13 Aug 2010 08:54:18 +0200, Ludovic Brenta <ludovic(a)ludovic-brenta.org> a écrit: > Yes, I did a _G here recently; I let the coding standard of Eurocontrol > (my day job) influence me. The coding standard says *_G for generics, > *_T for secondary types and just T for types. Hence: > > package S_Expression is -- singlular > type T is ...; -- the primary type, S_Expression.T > generic ... > package Serialization_G is ... > end Serialization_G; > private > type Internal_T is ...; -- a secondary (helper) type > end S_Expression; They seems to have an affinity for very short names. This would need evaluation (may be good at some point, less at some others) > Over the years I grew used to it and now I like it. One of the > advantages is that you don't have to struggle to find meaningful names > for parameters; e.g. you can say: > > procedure Foo (Internal : out Internal_T) is ... > end Foo; For that one, the merit does not come to _T, but rather to _Any_Suffix. We've talked about it already, this was about the _Type suffix. This _T works the same way. -- There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.
From: Yannick Duchêne (Hibou57) on 13 Aug 2010 09:41 Le Fri, 13 Aug 2010 10:40:57 +0200, Dmitry A. Kazakov <mailbox(a)dmitry-kazakov.de> a écrit: > Do you mean the use case or the offending code? I cannot say for the > latter > because I have no idea when it happens and if the code is legal [*]. The > simplest possible use case is the diamond diagram of generic packages > [**]: > > A > / \ > B C > \ / > D > > In the specification of D you have to constrain B and C to the same A. This may also occurs if you wanna do some Mixins. This was how I came to it the first if my mind is right. > ** We were told how dreadful the diamond is, so bad that Ada may not > allow > to have MI, but for sacred generics anything is perfectly OK! Did not understood this sentence, at least the last âbut for sacred generics anything is perfectly OK!â -- There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.
From: Dmitry A. Kazakov on 13 Aug 2010 09:48
On Fri, 13 Aug 2010 15:31:30 +0200, Yannick Duch�ne (Hibou57) wrote: > You mean the _G suffis became a somewhat de-facto standard ? I meant the prefix Generic_. However the standard has no clear policy on that: Ada.Text_IO.Integer_IO Ada.Containers.Doubly_Linked_Lists Ada.Numerics.Generic_Complex_Arrays >> Sometimes you need to "rename" formal types as well: >> >> generic >> type Foo is ... >> package Generic_S is >> subtype Foo_Of is Foo; -- What a mess! > > We already talked about these cases. Do you remember the thread's title ? > (I would like to get it back to read it again). I think it popped up more than once. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de |