From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9def0a9c238c7bd8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-12 10:27:55 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!sunqbc.risq.qc.ca!news.maxwell.syr.edu!newsfeed.slurp.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Ada 0x Wish List References: Organization: Multimedia X-Newsreader: trn 4.0-test72 (19 April 1999) From: cts@kampong.aedinc.net ((null)) Message-ID: Date: Mon, 12 Feb 2001 18:22:04 GMT NNTP-Posting-Host: 208.4.231.188 X-Trace: newsfeed.slurp.net 982002124 208.4.231.188 (Mon, 12 Feb 2001 12:22:04 CDT) NNTP-Posting-Date: Mon, 12 Feb 2001 12:22:04 CDT Xref: supernews.google.com comp.lang.ada:5182 Date: 2001-02-12T18:22:04+00:00 List-Id: In article , Peter Richtmyer 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 --------------------------------+------------------------------------