comp.lang.ada
 help / color / mirror / Atom feed
* no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
@ 2018-04-08  0:32 Mehdi Saada
  2018-04-08  6:50 ` J-P. Rosen
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Mehdi Saada @ 2018-04-08  0:32 UTC (permalink / raw)


I just realized one can't do that:

generic
with procedure instance_of_generic_procedure is new generic_procedure;
...

The rules say (my compilator is in trouble, can't try):
formal_subprogram_declaration ::= formal_concrete_subprogram_declaration
    | formal_abstract_subprogram_declaration
formal_concrete_subprogram_declaration ::= 
     with subprogram_specification [is subprogram_default]
        [aspect_specification];
formal_abstract_subprogram_declaration ::= 
     with subprogram_specification is abstract [subprogram_default]
        [aspect_specification];
subprogram_default ::= default_name | <> | null
default_name ::= name

What ?? I have trouble figuring how it could have been forgotten. Any parenthood for instances of generic compilation units, packages or subprograms, should be possible to mention. For uniformity (or Heaven, no different)'s sake, also it would enable to check in particular things like:
generic
  type Item(<>);
  type Item_access is access Item;
  with procedure Free is new Unchecked_Deallocation (Item, Item_access);
package Smart_pointers ... Yes, I thought of that limitation with Jere's help with https://stackoverflow.com/questions/49660425/ada-difficulties-with-generics-incomplete-types-and-self-referencing-structure .

I hope I wasn't gravely mistaken, or else I'll probably never come here again because of shame...


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08  0:32 no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible ! Mehdi Saada
@ 2018-04-08  6:50 ` J-P. Rosen
  2018-04-09 23:43   ` Shark8
  2018-04-08 11:15 ` Mehdi Saada
  2018-04-12  8:56 ` Marius Amado-Alves
  2 siblings, 1 reply; 14+ messages in thread
From: J-P. Rosen @ 2018-04-08  6:50 UTC (permalink / raw)


Le 08/04/2018 à 02:32, Mehdi Saada a écrit :
> I just realized one can't do that:
> 
> generic
> with procedure instance_of_generic_procedure is new generic_procedure;
> ...
Of course - because it would be useless. The only thing you know from
the specification of a generic subprogram is its profile, and you can
import any procedure with an appropriate profile. While restrict to
those that are in addition an instantiation of a given generic?

You have been mistaken by the case of packages. While it is easy to
define the matching of subprograms, the matching of packages would be
almost impossible to define - unless the package in an instantiation of
a generic, in which case it obviously matches the generic.

When Ada95 was designed, there was a demand for passing packages the
same way as subprograms (already present in Ada83). It appeared that
this was possible only for packages that were built from the same
generic. There is no such problem with subprograms.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08  0:32 no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible ! Mehdi Saada
  2018-04-08  6:50 ` J-P. Rosen
@ 2018-04-08 11:15 ` Mehdi Saada
  2018-04-08 11:46   ` Jere
  2018-04-12  8:56 ` Marius Amado-Alves
  2 siblings, 1 reply; 14+ messages in thread
From: Mehdi Saada @ 2018-04-08 11:15 UTC (permalink / raw)


I understand your point, but there are special cases... namely Unchechecked_deallocation, unchecked_conversion. In the example above, I can't be sure the "Free" provided will be an effective deallocation procedure.
Sure, I don't see that many other examples, in fact I see none, but other people COULD have found that useful. Well, that wouldn't have changed the world. I won't argue with that :-P


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08 11:15 ` Mehdi Saada
@ 2018-04-08 11:46   ` Jere
  2018-04-08 13:47     ` Mehdi Saada
  0 siblings, 1 reply; 14+ messages in thread
From: Jere @ 2018-04-08 11:46 UTC (permalink / raw)


On Sunday, April 8, 2018 at 7:15:15 AM UTC-4, Mehdi Saada wrote:
> I understand your point, but there are special cases... namely 
> Unchechecked_deallocation, unchecked_conversion. In the example above, 
> I can't be sure the "Free" provided will be an effective deallocation procedure.

Something to consider in your specific case:  For smart pointers, you may
not want to restrict the user to unchecked_deallocation exclusively.  Consider
a smart pointer to a file or a serial port.  You may want your finalize
procedure to not only deallocate but to also close the resource (if it
is open). In those cases you'll need a slightly more complex finalization
routine.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08 11:46   ` Jere
@ 2018-04-08 13:47     ` Mehdi Saada
  0 siblings, 0 replies; 14+ messages in thread
From: Mehdi Saada @ 2018-04-08 13:47 UTC (permalink / raw)


You're right... Sometimes, "pretty" ideas in theory are useless in practice.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08  6:50 ` J-P. Rosen
@ 2018-04-09 23:43   ` Shark8
  0 siblings, 0 replies; 14+ messages in thread
From: Shark8 @ 2018-04-09 23:43 UTC (permalink / raw)


On Sunday, April 8, 2018 at 12:50:15 AM UTC-6, J-P. Rosen wrote:
> Le 08/04/2018 à 02:32, Mehdi Saada a écrit :
> > I just realized one can't do that:
> > 
> > generic
> > with procedure instance_of_generic_procedure is new generic_procedure;
> > ...
> Of course - because it would be useless. The only thing you know from
> the specification of a generic subprogram is its profile, and you can
> import any procedure with an appropriate profile. While restrict to
> those that are in addition an instantiation of a given generic?

The idea behind my proposal for automatic/default instantiation was addressing this, as well as allowing the formal parameters to direct the implicit instantiation.

GENERIC
  TYPE Parameter_Type IS (<>);
PROCEDURE Generic_Swap( A, B : Parameter_Type );
PROCEDURE Generic_Swap( A, B : Parameter_Type ) IS
  C : Constant Parameter_Type:= A;
BEGIN
  A:= B;
  B:= C;
END Generic_Swap;

GENERIC
  TYPE Something IS (<>);
  USE PROCEDURE Swap IS NEW Generic_Swap( Parameter_Type => Something );
PACKAGE Example IS
--...
END Example;

Which would allow a more uniform syntax, which is what this seems to be about, as well as allow Example.Swap to be implicitly instantiated the instantiation of Example.

> You have been mistaken by the case of packages. While it is easy to
> define the matching of subprograms, the matching of packages would be
> almost impossible to define - unless the package in an instantiation of
> a generic, in which case it obviously matches the generic.
> 
> When Ada95 was designed, there was a demand for passing packages the
> same way as subprograms (already present in Ada83). It appeared that
> this was possible only for packages that were built from the same
> generic. There is no such problem with subprograms.

There was an extension in the iAPX 432 of "Package Types" that have an interesting correlation to this demand, IMO -- if you want to kno more, here's the manual:  http://bitsavers.informatik.uni-stuttgart.de/components/intel/iAPX_432/172283-001_Reference_Manual_for_the_Intel_432_Extensions_to_Ada_Dec81.pdf


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-08  0:32 no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible ! Mehdi Saada
  2018-04-08  6:50 ` J-P. Rosen
  2018-04-08 11:15 ` Mehdi Saada
@ 2018-04-12  8:56 ` Marius Amado-Alves
  2018-04-12 10:14   ` Mehdi Saada
  2 siblings, 1 reply; 14+ messages in thread
From: Marius Amado-Alves @ 2018-04-12  8:56 UTC (permalink / raw)


Semigodess Ada is so good at her "overriding concern" of "programming as a human activity" that she often tricks us poor humans into expecting she will accept any construct that seems logical and intuitive to us. Alas she is not perfect...

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-12  8:56 ` Marius Amado-Alves
@ 2018-04-12 10:14   ` Mehdi Saada
  2018-04-13  0:37     ` Shark8
  0 siblings, 1 reply; 14+ messages in thread
From: Mehdi Saada @ 2018-04-12 10:14 UTC (permalink / raw)


>  USE PROCEDURE Swap IS NEW Generic_Swap( Parameter_Type => Something );
Hum, just to be sure, does the above mean "if a swap procedure is not provided, use this one" ?
Like I asked in a mail, did that proposition happen to be formalized in a AI ?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-12 10:14   ` Mehdi Saada
@ 2018-04-13  0:37     ` Shark8
  2018-04-13 12:34       ` Mehdi Saada
  0 siblings, 1 reply; 14+ messages in thread
From: Shark8 @ 2018-04-13  0:37 UTC (permalink / raw)


On Thursday, April 12, 2018 at 4:14:47 AM UTC-6, Mehdi Saada wrote:
> >  USE PROCEDURE Swap IS NEW Generic_Swap( Parameter_Type => Something );
> Hum, just to be sure, does the above mean "if a swap procedure is not provided, use this one" ?

A little bit more than that; more: "if a swap procedure is not provided, instantiate the generic with the given parameters and use that one".

> Like I asked in a mail, did that proposition happen to be formalized in a AI ?

I replied to that message, with what became the AI.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-13  0:37     ` Shark8
@ 2018-04-13 12:34       ` Mehdi Saada
  2018-04-13 15:57         ` Mehdi Saada
  2018-04-14  0:00         ` Randy Brukardt
  0 siblings, 2 replies; 14+ messages in thread
From: Mehdi Saada @ 2018-04-13 12:34 UTC (permalink / raw)


It was lost in the huge list of meaningless stuff... I read it, and LOVE IT. Everything is clear from the get-go. But I do have some comments and suggestions. Probably you will find them silly or unrealistic, but please bear with it and tell me your opinion.
From your AI the only thing I’m not a huge fan of, is the use of ... "USE".

I'll make them here, so that people might review them and scold me on how silly I am (I'm prepared, it's ok...).

1) defaults for types themselves :
      Type Item_type is private or use some_known_type; Anything might be provided in default or by the user, but the generic might only use the properties mentioned in the contract (here, being definite, non-limited and non-abstract).

Honestly why isn't it already allowed ? Implementation hurdle ?

2)  with Package Object_Stack  is new Generic_Stack(PostScript_Object)
                 or use Generic_stack (Postscript_object);
Granted this one’s not perfect: there's a repetition, but it doesn't say exactly the same: first "generic_stack(...)" is a contract, the second one is the default indication.
I stumbled on the rule « It is all or nothing: if you specify the generic parameters, you must specify all of them. Similarly, if you specify no parameters and no box, then all the generic formal parameters of Q must have defaults. The actual package must, of course, match these constraints. » (ada wikibook). I don’t know why they set that… How would that be difficult to implement to allow some parameters to be given or others let to default, provided named association is used for both kinds, to remove any ambiguity ?
IF that rule could disappear, one could write :
with package Object_Stack is new Generic_Stack(Item_type => PostScript_Object, others => <>  [others parameters let to default] or use Generic_Stack([complete parameters list here])
or :
with package Object_Stack is new Generic_Stack(others => <> [or simply <>])  or use Generic_Stack(…) ;
Much more useful than before.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-13 12:34       ` Mehdi Saada
@ 2018-04-13 15:57         ` Mehdi Saada
  2018-04-13 23:59           ` Randy Brukardt
  2018-04-14  0:00         ` Randy Brukardt
  1 sibling, 1 reply; 14+ messages in thread
From: Mehdi Saada @ 2018-04-13 15:57 UTC (permalink / raw)


I shall add that removing that rule of "all or none" is necessary ( possible or not :-) ) because,
considering GP1 which needs GP2:
generic
   type T1 is private
   with package P2 is new GP2(T1...)
package GP1... end GP1;

some parameters of GP2 use or concern T1 (are logically related to T1), but some others, might they have defaults or not, might be used for parts of GP2 totally unrelated to T1. This fact is already expressed in contracts (not sure the term is right, I mean "everything between "generic" and "package generic_package_name is ..."), so I don't think a priori it would entail more checks for formal parameters coherence.

Hope I didn't spout rubbishes.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-13 15:57         ` Mehdi Saada
@ 2018-04-13 23:59           ` Randy Brukardt
  0 siblings, 0 replies; 14+ messages in thread
From: Randy Brukardt @ 2018-04-13 23:59 UTC (permalink / raw)


That was changed in Ada 2005. - Randy

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:b4157ddb-9783-4b64-a165-1f7af26aee9f@googlegroups.com...
I shall add that removing that rule of "all or none" is necessary ( possible 
or not :-) ) because,
considering GP1 which needs GP2:
generic
   type T1 is private
   with package P2 is new GP2(T1...)
package GP1... end GP1;

some parameters of GP2 use or concern T1 (are logically related to T1), but 
some others, might they have defaults or not, might be used for parts of GP2 
totally unrelated to T1. This fact is already expressed in contracts (not 
sure the term is right, I mean "everything between "generic" and "package 
generic_package_name is ..."), so I don't think a priori it would entail 
more checks for formal parameters coherence.

Hope I didn't spout rubbishes. 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-13 12:34       ` Mehdi Saada
  2018-04-13 15:57         ` Mehdi Saada
@ 2018-04-14  0:00         ` Randy Brukardt
  2018-04-14  6:00           ` Mehdi Saada
  1 sibling, 1 reply; 14+ messages in thread
From: Randy Brukardt @ 2018-04-14  0:00 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:c5ca4f5c-65db-4e6c-bfc1-15dc903a380b@googlegroups.com...
>1) defaults for types themselves :

That was proposed for Ada 2005, but we couldn't agree on syntax (some people 
hate "use" for this purpose).

It's been reraised for Ada 2020. We'll see if it gets anywhere (I believe it 
made the initial cut, but that was without discussion or wording).

              Randy.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible !
  2018-04-14  0:00         ` Randy Brukardt
@ 2018-04-14  6:00           ` Mehdi Saada
  0 siblings, 0 replies; 14+ messages in thread
From: Mehdi Saada @ 2018-04-14  6:00 UTC (permalink / raw)


That's one of the first AI I read with delight from beginning to end, I forgot. and I see no one complained about "or use" (not "use" alone) in particular. There might still hope.
Damn wikibook, one way to let people make fool of themselves :-D . Unintentionally of course. The last AI about default is http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0205-1.txt, so that people won't search it. I got all pumped up and all, but at least it shows even beginner can understand what the most intuitive change might be ? I'll pray for "or use", it would be a shame (or even a scam ...) if it's not approved.

I wonder, _how_the_heck_ it might have been deemed "not important enough" to settle on something ??


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-04-14  6:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-08  0:32 no, it can't be, there's no "with procedure instance_of_generic_procedure is new generic_procedure;" ? Impossible ! Mehdi Saada
2018-04-08  6:50 ` J-P. Rosen
2018-04-09 23:43   ` Shark8
2018-04-08 11:15 ` Mehdi Saada
2018-04-08 11:46   ` Jere
2018-04-08 13:47     ` Mehdi Saada
2018-04-12  8:56 ` Marius Amado-Alves
2018-04-12 10:14   ` Mehdi Saada
2018-04-13  0:37     ` Shark8
2018-04-13 12:34       ` Mehdi Saada
2018-04-13 15:57         ` Mehdi Saada
2018-04-13 23:59           ` Randy Brukardt
2018-04-14  0:00         ` Randy Brukardt
2018-04-14  6:00           ` Mehdi Saada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox