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=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73f097f1e2686cf5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-07 06:22:01 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!out.nntp.be!propagator-SanJose!news-in!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: <9n9r4c$srt$1@snipp.uninett.no> Subject: Re: Simplest way to protect a variable ? Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Fri, 07 Sep 2001 09:21:51 EDT Organization: http://www.newsranger.com Date: Fri, 07 Sep 2001 13:21:51 GMT Xref: archiver1.google.com comp.lang.ada:12890 Date: 2001-09-07T13:21:51+00:00 List-Id: In article <9n9r4c$srt$1@snipp.uninett.no>, Reinert Korsnes says... >Let's say I initiate a "global" variable, A (for example an array), by >calling a procedure (which may read data from a file). And I want to be >sure that the content (value) of this variable is not changed by >another procedure. The variable is "global" in the sense that it is >available in many many other routines. If I take the literal interpretation of what you are saying, you want one routine to be able to set it once, and everyone else only having read-only access. The easiest way to do that is to declare it as a constant in its package spec. If you need a function to initialize it, put the function in a package that doesn't depend on your package's body, and do a pramga elaborate_all on its package when you "with" it. A more flexible way to do it is to put the global variable inside the package body of the setter. For all the read-only clients, provide a function in the package spec that returns the current value of the variable. Code in the package body can now muck with your global at will, but no-one else can (unless you provide them a routine to do so). Among other benifits, this allows you to change the implementation of your "global" without affecting your read-only clients. --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com