comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Specialization
Date: 01 Jun 2002 15:50:10 -0400
Date: 2002-06-01T19:57:34+00:00	[thread overview]
Message-ID: <un0ue22z1.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: x7vit52exe1.fsf@pushface.org

Simon Wright <simon@pushface.org> writes:

> Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:
> 
> > You could actually give it a default, but the users would have to make
> > that object visible, and use your name for it; not much better than
> > simply supplying the parameter at instantiation.
> 
> I don't think so, it's their type not mine

Hmm. You seem to be correct. I was mislead by ARM 12.4:

  2.      formal_object_declaration ::=
             defining_identifier_list : mode subtype_mark
               [:= default_expression];

                          *Name Resolution Rules*

  3. The expected type for the default_expression, if any, of a formal
     object is the type of the formal object.

I assumed the 'default_expression' was resolved at the point of instantiation,
not at the point of declaration of the generic. But I now see that
doesn't make sense.

Learn something new every day :).

Here's code to prove your point. It fails because 'A_Null_Value' is
not visible at it's first occurance.

with Ada.Text_IO; use Ada.Text_IO;
procedure Formal_Default
is
   type My_Type is record
      Foo : Integer;
   end record;

   generic
      type Gen_Type is private;
      Null_Value : in Gen_Type := A_Null_Value; -- wrong; not visible.
      with function Image (Item : in Gen_Type) return String is <>;
   procedure Gen_Bar;

   procedure Gen_Bar
   is begin
      Put_Line (Image (Null_Value));
   end Gen_Bar;

   function Image (Item : in My_Type) return String
   is begin
      return Integer'Image (Item.Foo);
   end Image;

   A_Null_Value : constant My_Type := (Foo => 0);

   procedure Bar is new Gen_Bar (My_Type);
begin
   Bar;
end Formal_Default;


-- 
-- Stephe



  reply	other threads:[~2002-06-01 19:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-30 12:39 Specialization Baugereau
2002-05-30 17:09 ` Specialization Ted Dennison
2002-05-30 17:29   ` Specialization Baugereau
2002-05-30 19:20     ` Specialization Stephen Leake
2002-05-30 19:48       ` Specialization Baugereau
2002-05-31  1:18         ` Specialization Jim Rogers
2002-05-31  5:41           ` Specialization Sergey Koshcheyev
2002-05-31 11:36             ` Specialization Baugereau
2002-05-31 14:08             ` Specialization Jim Rogers
2002-05-31 16:45               ` Specialization Hyman Rosen
2002-05-31 17:05               ` Specialization Sergey Koshcheyev
2002-05-31 17:40                 ` Specialization Hyman Rosen
2002-05-31 20:04                   ` Specialization Sergey Koshcheyev
2002-05-31 21:25                     ` Specialization Hyman Rosen
2002-05-31 13:27         ` Specialization Stephen Leake
2002-05-31 19:46           ` Specialization Simon Wright
2002-06-01 15:30             ` Specialization Stephen Leake
2002-05-31 19:44   ` Specialization Simon Wright
2002-06-01 15:25     ` Specialization Stephen Leake
2002-06-01 17:12       ` Specialization Simon Wright
2002-06-01 19:50         ` Stephen Leake [this message]
2002-05-30 17:46 ` Specialization Toshitaka Kumano
replies disabled

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