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=2.6 required=5.0 tests=BAYES_20,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!software.org!collard From: collard@software.org (David Collard) Newsgroups: comp.lang.ada Subject: Re: Readonly variables in Ada? Message-ID: <1261@software.software.org> Date: 5 Jun 90 16:22:52 GMT References: <1990Jun5.085654.920@lth.se> Sender: news@software.org Reply-To: collard@software.org (David Collard) Organization: Software Productivity Consortium, Herndon, Virginia List-Id: In article <1990Jun5.085654.920@lth.se> collberg@DNA.LTH.Se (Christian S. Collberg) writes: > Is it possible to declare (the equivalent of) an exported readonly > variable in Ada? I'm referring to something similar to the READ_ONLY > attribute present in Mesa. I'm having a hard time reading the > package P; > type T is limited private; > v : T; -- We want a client of P to be able to > -- perform any operation on v, except > -- assignment. > private > type T is BOOLEAN; > end P; I think, for a read only VARIABLE, there is an easier answer -- the type can be visible, but declare the variable in the body of the package and only provide an interface to read it. package P is function T return Boolean; end P; package body P is Static_Package_Variable : Boolean; function T return Boolean is begin return Static_Package_Variable; end T; end P; with P; procedure P_User is begin if P.T then --Legal null; end if; P.Static_Package_Variable := False; -- Illegal because the variable is not visible. end P_User; A end P_User; -- ----------------------------------------------------------------------- D. Thor Collard Internet: collard@software.org Software Productivity Consortium UUNET: ...!uunet!software!collard 2214 Rock Hill Rd, Herndon VA 22070