comp.lang.ada
 help / color / mirror / Atom feed
From: cts@kampong.aedinc.net ((null))
Subject: Re: Ada 0x Wish List
Date: Mon, 12 Feb 2001 18:22:04 GMT
Date: 2001-02-12T18:22:04+00:00	[thread overview]
Message-ID: <gRVh6.326$Zb7.426@newsfeed.slurp.net> (raw)
In-Reply-To: RKIh6.3190$j45.247550@e3500-chi1.usenetserver.com

In article <RKIh6.3190$j45.247550@e3500-chi1.usenetserver.com>,
Peter Richtmyer <pmr@efortress.com> wrote:
>
>2) In a subroutine, would like to be able to declare variables that are
>"persistent", like C "static" variables and only used by the one subroutine.
>Presently this data must be in the package body (or spec, or some other
>package spec), where it is visible and updatable by other routines,
>even though it is intended for use by one routine only. (Or is there
>another easy way to do this already?)


Just wrap the subroutine in a sub-package.  It does require a bit
more typing (~7 more lines of code) but my typing is getting better
everyday. :-)


--- foo.ads
package Foo is 
   procedure Do_Stuff;
   function Baz return Integer;
end Foo;


--- foo.adb
with Ada.Text_IO; use Ada.Text_IO;

package body Foo is 
   
   package Bar is 
      function Baz return Integer;
   private
      -- The variable I in this subpackage 
      -- will 'remember' it's value between calls 
      -- to Baz.  
      I: Integer := 0;
   end Bar;
   package body Bar is 
      function Baz return Integer is 
      begin
         I := I+3;
         return I;
      end Baz;
   end Bar;
   function Baz return Integer renames Bar.Baz;
   
   procedure Do_Stuff is 
   begin
      Put_Line("baz returned " & Integer'Image(Baz));
      for I in 1..10 loop
         Put_Line("I is " & Integer'Image(I) 
                  & " and baz returned " & Integer'Image(Baz));
      end loop;
   end run;
end Foo;

      

-- 
=======================================================================
 Life is short.                  | Craig Spannring 
      Bike hard, ski fast.       | cts@internetcds.com
 --------------------------------+------------------------------------



  parent reply	other threads:[~2001-02-12 18:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-12  3:25 Ada 0x Wish List Peter Richtmyer
2001-02-12  4:22 ` Jeffrey Carter
2001-02-12  7:23   ` Dale Stanbrough
2001-02-12 13:04     ` Preben Randhol
2001-02-13 16:33     ` Robert Deininger
2001-02-13 18:15       ` Keith Thompson
2001-02-12  7:39 ` Florian Weimer
2001-02-12 13:18   ` Steve Folly
2001-02-12 15:25   ` Arthur Schwarz
2001-02-12 14:29 ` John English
2001-02-13  8:31   ` Dr Adrian Wrigley
2001-02-13 20:46   ` Fraser Wilson
2001-02-13 22:06     ` Larry Hazel
2001-02-13 22:45       ` Fraser Wilson
2001-02-13 23:14         ` Larry Hazel
2001-02-13 23:59           ` David C. Hoos, Sr.
2001-02-14  1:22             ` Larry Hazel
2001-02-13 23:51     ` Keith Thompson
2001-02-14 11:23     ` David C. Hoos, Sr.
2001-02-15 22:01       ` Georg Bauhaus
2001-02-15 22:14         ` Marin David Condic
2001-02-17  8:43     ` Dr Adrian Wrigley
2001-02-12 16:08 ` Steve Folly
2001-02-12 17:53   ` Lao Xiao Hai
2001-02-12 18:22 ` (null) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-02-15  1:33 Beard, Frank
replies disabled

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