comp.lang.ada
 help / color / mirror / Atom feed
* Re: generic formal object parameters of mode 'in out'
  2000-11-06  0:00 generic formal object parameters of mode 'in out' Steve Folly
@ 2000-11-06  0:00 ` Robert A Duff
  2000-11-06  0:00 ` mark_lundquist
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 2000-11-06  0:00 UTC (permalink / raw)


steve.folly@rdel.co.uk (Steve Folly) writes:

> While reading the ARM today I noticed it's possible to specify generic
> formal objects of mode 'in out'.
> 
> I was just wondering what use this could have?

Only a little.

> Am I right in thinking that by making Template an 'in out', I don't
> need The_Template.

No.  The visibility rules have nothing to do with the mode.
The fact that you can't see the formals from outside is an
annoyance, but no big deal, and is not affected by 'in' vs
'in out'.

> And, if it is now an 'in out', can I change Template at any time
> outside of the instantiation (or inside it) ?

It's a (view of a) variable, and so can be modified.

- Bob




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

* Re: generic formal object parameters of mode 'in out'
  2000-11-06  0:00 generic formal object parameters of mode 'in out' Steve Folly
  2000-11-06  0:00 ` Robert A Duff
@ 2000-11-06  0:00 ` mark_lundquist
  1 sibling, 0 replies; 3+ messages in thread
From: mark_lundquist @ 2000-11-06  0:00 UTC (permalink / raw)


In article <3a06dc1c.259466533@news.rrds.co.uk>,
  steve.folly@rdel.co.uk (Steve Folly) wrote:

> In my program I have the following generic package...
>
> subtype Template_String is string(1..4);
>
> generic
>    type T is private;
>    Default : T;
>    Template : Template_String;
> package P
>    The_Template : constant String := Template;
>    .
>    .
> end P;
>
> We have had to declare The_Template because we've found that the
> parameters are not visible from an instantiation, ie.
>
> declare
>   package X is new P ( T => Integer, Default => 0, Template => "NNNN"
> );
> begin
>    Ada.Text_Io.Put_Line("The template is " & X.Template ); -- uh oh!
>    Ada.Text_Io.Put_Line("The template is " & X.The_Template ); -- OK
> end;
>
> Am I right in thinking that by making Template an 'in out', I don't
> need The_Template.

Nope, sorry.  Making Template 'in out' won't change its visibility.  If
you make Template 'in out', then you will get a compile error on your
instantiation above, because an 'in out' generic formal requires a
variable (view of an) object as the actual (because the generic is
allowed to change the value of the actual).  So instantiating it on a
constant expression like "NNNN" isn't legal.

But... I'd still get rid of The_Template, anyway!

Having P re-export one of its own generic parameters strikes me as
gimmiky and something that doesn't really make the program clearer.
Since, by construction, the actuals are visible wherever the
instantiation itself is visible, why not just refer to the actual?  You
don't need a workaround for not being able to refer to the formal.

That is:

   declare
      Template : constant String := "NNNN";
      package X is new P (T => Integer, Default => 0, Template =>
Template);
    begin
        Ada.Text_Io.Put_Line ("The template is " & Template);
    end;

To me that seems less roundabout... but to each his/her own...

> And, if it is now an 'in out', can I change Template at any time
> outside of the instantiation (or inside it) ?

Right.

have fun,
mark

Mark Lundquist
Rational Software



Sent via Deja.com http://www.deja.com/
Before you buy.




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

* generic formal object parameters of mode 'in out'
@ 2000-11-06  0:00 Steve Folly
  2000-11-06  0:00 ` Robert A Duff
  2000-11-06  0:00 ` mark_lundquist
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Folly @ 2000-11-06  0:00 UTC (permalink / raw)


Hi,

While reading the ARM today I noticed it's possible to specify generic
formal objects of mode 'in out'.

I was just wondering what use this could have?

Para 12.4 [1b] does state that it's like a renaming declaration of the
explicit actual parameter.

In my program I have the following generic package...

subtype Template_String is string(1..4);

generic
   type T is private;
   Default : T;
   Template : Template_String;
package P
   The_Template : constant String := Template;
   .
   .
end P;


We have had to declare The_Template because we've found that the
parameters are not visible from an instantiation, ie.

declare
  package X is new P ( T => Integer, Default => 0, Template => "NNNN"
);
begin
   Ada.Text_Io.Put_Line("The template is " & X.Template ); -- uh oh!
   Ada.Text_Io.Put_Line("The template is " & X.The_Template ); -- OK
end;

Am I right in thinking that by making Template an 'in out', I don't
need The_Template.

And, if it is now an 'in out', can I change Template at any time
outside of the instantiation (or inside it) ?

Just my disjointed ramblings at the end of long day...

Cheers,
Steve Folly.




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

end of thread, other threads:[~2000-11-06  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-06  0:00 generic formal object parameters of mode 'in out' Steve Folly
2000-11-06  0:00 ` Robert A Duff
2000-11-06  0:00 ` mark_lundquist

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