comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Generic operation and prefixed notation
Date: Mon, 14 Jun 2010 20:09:06 +0200
Date: 2010-06-14T20:09:05+02:00	[thread overview]
Message-ID: <w1tyv5duwnhe$.1rwxjto44oy98$.dlg@40tude.net> (raw)
In-Reply-To: hv5puu$2dp1$1@adenine.netfront.net

On Mon, 14 Jun 2010 19:47:09 +0200, Marek Janukowicz wrote:

> I'm still working on a problem I asked about last week (thanks for all the 
> answers). Another question that arose recently: is there any way of calling 
> an instantiation of generic operation with prefixed notation?
> 
> Given a simplified example:
> 
>   type Model is tagged record
>     null
>   end record;
> 
>   generic
>     Attr_Name : String;
>   procedure Get_Attribute( M : Model );
> 
>   procedure Get_Name is new Get_Attribute( "Name" );
> 
> Now I can call it with:
>   Get_Name( M );
> 
> but I'd rather use
>   M.Get_Name;
> 
> which complains about Get_Name not being present.
> 
> Is there any other way to achieve it?

Prefix notation is considered harmful. Anyway,. you need the operation
primitive:

One unit, declares the interface:

   type Abstract_Model is abstract tagged null record;
   procedure Get_Name (M : Abstract_Model) is abstract;

Same or another unit, provides a generic implementation:
   generic
      type Model_Type is new Abstract_Model with private;
      Attr_Name : String;
   procedure Get_Attribute (M : Model_Type);

Yet another unit brings both together:

   type Model is new Abstract_Model with null record;
   overriding procedure Get_Name (M : Model);

In its body:

   procedure Get_Name_Implementation is new Get_Attribute (Model, "Name");
   procedure Get_Name (M : Model) renames Get_Name_Implementation;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-06-14 18:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14 17:47 Generic operation and prefixed notation Marek Janukowicz
2010-06-14 18:09 ` Dmitry A. Kazakov [this message]
2010-06-14 18:11 ` Yannick Duchêne (Hibou57)
2010-06-15  1:14   ` Adam Beneschan
replies disabled

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