comp.lang.ada
 help / color / mirror / Atom feed
* Re: Generic default parameters
@ 2002-05-14  4:57 Grein, Christoph
  2002-05-14 10:23 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 29+ messages in thread
From: Grein, Christoph @ 2002-05-14  4:57 UTC (permalink / raw)


> > 6. A more liberal matching of actual subprograms against formal ones.
> > If some parameters of the actual subrogram have defaults, then they
> > can be absent in the formal one.
> > 
> > generic
> >    with procedure Put (Item  : in Object) is <>;
> > package Foo ...
> > 
> > Then an instantiation with Integer_IO.Put:    <-------- #2
> > 
> > procedure Put
> > (  Item  : in Num;
> >    Width : in Field := Default_Width;
> >    Base  : in Number_Base := Default_Base
> > );
> > 
> > should be legal.
> 
> I like this. I don't see how it could be a problem.

I do see problems with this proposal. First of all it would be a major upwardly 
incompatible change and break old code - a NONO for the ARG.

Imagine Ada95 code that defines

  procedure Put (Item: in Num) is  -- #1
  begin
    Put (Item, Default_Width, Default_Base);  -- the Int_IO one, #2
  end Put;

  package Foo_Inst is new Foo;

Currently this is OK since only #1 matches. With this proposal, #1 and #2 would 
be candidates (assuming the latter is directly visible), so the compiler would 
not know which to take. This breakes old code.

OK, you could complicate the rules by stating that if there is a match without 
defaults, this one is preferred, then it would not break old code. But then you 
would introduce another case where adding or removing a declaration silently 
changes the code. We surely do not want another such rule.

[Beaujolais effect, where adding and removing a use clause changes the legal 
behaviour, has been removed from Ada with the 95 standard.
Sadly enough, a new effect has been introduced, where adding and removing a with 
clause can now change the legal behaviour (think of child packages) - isn't this 
called the Ripple effect?
We really do not want another such effect. If you think more closely about it, 
such a preference rule would reintroduce the Beaujolais effect.]

This being the case, it seems useless to discuss how matching rules for 
subprograms with defaulted parameters should be defined - they are not so 
obvious for me.




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: Generic default parameters
@ 2002-05-14 11:03 Grein, Christoph
  2002-05-14 12:01 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 29+ messages in thread
From: Grein, Christoph @ 2002-05-14 11:03 UTC (permalink / raw)


> >I do see problems with this proposal. First of all it would be a major 
upwardly 
> >incompatible change and break old code - a NONO for the ARG.
> ...
> True. It would make some old code ambiguous. However the ambiguity can
> be relatively easily resolved.

Easy or not, only if absolutely necessary would the ARG be willing to change the 
language in a way that is upwardly incompatible. This proposal does not seem 
worth it.

> >This being the case, it seems useless to discuss how matching rules for 
> >subprograms with defaulted parameters should be defined - they are not so 
> >obvious for me.
> 
> In fact I thought that the matching rules for subprogram renaming
> should be relaxed with regard of default values. Presently, generics
> just use that rules. I wished these rules were same as ones for
> subprogram calls. Maybe, as close as:
> 
>    function Int_Sqrt (X : Integer) renames Sqrt (Float (X));
>    procedure Debug (X : Integer)
>       renames Put_Line
>          (File=>My_File; Item=>Integer'Image (X));

This is invalid syntax (I can imagine what you mean - it's a mess). But the 
rules would not be so simple. Defaulted parameters need not come last (in this 
way you force named association when omitting parameters).

So would either subprogram

  procedure (X: S; Y: T := Def);
  procedure (X: T := Def; Y: S);

match

  procedure (W: S);

What about

  procedure (X: S; Y: S := Def);
  procedure (X: S := Def; Y: S);

Would they both match?



^ permalink raw reply	[flat|nested] 29+ messages in thread
* Generic default parameters
@ 2002-05-10 14:22 Thomas Wolf
  2002-05-10 16:38 ` Preben Randhol
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Thomas Wolf @ 2002-05-10 14:22 UTC (permalink / raw)



It seems I'm not alone with these ideas... so let's summarize
and see if we can get a halfway decent proposal for the ARG
out of the discussions:

Ada 95 lacks features for:

1. specifying a default type for generic formal type parameters

   The idea would be to allow something like

   generic
      type Something is range <> := Natural;

   and if an instantiation does *not* supply an actual for
   'Something', 'Natural' will be taken.

2. specifying a default for generic formal package parameters:

   generic
      with package X is new Y (<>) := Z;

   where Z of course would have to be an instantiation of Y.

   Or maybe even

   generic
      with package X is new Y (<>) := Y (Param1 => Default1,
                                         Param2 => Default2,
                                         ...);

   i.e., allow the default to be an anonymous instance?
   (I guess, the first variant is sufficient, and the second
   would only unnecessarily complicate matters.)

3. specify a default for a generic formal "in out" object:

   with System.Storage_Pools;
   generic
      type Something is private;
      Pool : in out System.Storage_Pools.Root_Storage_Pool'Class :=
         Some_Default_Pool_Instance;
   package X is
      type Some_Access is access all Something;
      for Some_Access'Storage_Pool use Pool;
      ...

4. providing defaults in a generic renaming:

   generic
     type Something is private;
   package A is ...

   generic package B renames A (Something => Integer);

   or even

   generic
     type Something is range <> := Natural;
   package C is ...

   generic package D renames C (Something => Integer);

5. Linked to (3) above: some way to specify a storage pool that
   is equal to whatever pool the compiler would use if no
   "for Some_Access'Storage_Pool use ..." clause was present, i.e.
   a generic way to refer to the standard storage pool of a type
   without referring to the type. Something like

   generic
      type Something is private;
      Pool : in out System.Storage_Pools.Root_Storage_Pool'Class := <>;
   package X is
      type Some_Access is access all Something;
      for Some_Access'Storage_Pool use Pool;
      ...

   and if an instantiation provides an actual for 'Pool', that will
   be taken as the storage pool of type 'Some_Access', but if an
   instantiation doesn't provide an actual, 'Some_Access' will use
   a standard storage pool.

   Not sure if point (5) makes sense, especially since it would be
   useful only for storage pools, but make no sense at all for other
   types...

Personally, I have encountered several occasions where I would have
liked to have some (or all) of these features. They'd help a lot in
writing general generics (:-) that still are simple to instantiate.
 
Comments, anyone? Would these things be worth to consider for inclusion
in the next Ada revision? 

-- 
-----------------------------------------------------------------
Thomas Wolf                          e-mail: t_wolf@angelfire.com




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

end of thread, other threads:[~2002-05-15 10:08 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-14  4:57 Generic default parameters Grein, Christoph
2002-05-14 10:23 ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2002-05-14 11:03 Grein, Christoph
2002-05-14 12:01 ` Dmitry A. Kazakov
2002-05-14 14:05   ` Stephen Leake
2002-05-15  8:44     ` Dmitry A. Kazakov
2002-05-10 14:22 Thomas Wolf
2002-05-10 16:38 ` Preben Randhol
2002-05-10 16:50   ` Marin David Condic
2002-05-11  9:29     ` Simon Wright
2002-05-13 15:03       ` Hyman Rosen
2002-05-11 12:28     ` Preben Randhol
2002-05-13 14:03       ` Marin David Condic
2002-05-13 14:49       ` Hyman Rosen
2002-05-10 19:04   ` Hyman Rosen
2002-05-11 12:23     ` Preben Randhol
2002-05-11 13:49       ` Larry Kilgallen
2002-05-13 14:06       ` Marin David Condic
2002-05-10 19:27   ` Randy Brukardt
2002-05-11 12:32     ` Preben Randhol
2002-05-10 22:14 ` Stephen Leake
2002-05-13  7:49   ` Thomas Wolf
2002-05-13  8:49 ` Dmitry A. Kazakov
2002-05-13 14:00   ` Stephen Leake
2002-05-13 15:21     ` Dmitry A. Kazakov
2002-05-13 16:42       ` Stephen Leake
2002-05-14 10:24         ` Dmitry A. Kazakov
2002-05-14 14:02           ` Stephen Leake
2002-05-15 10:08             ` Dmitry A. Kazakov

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