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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fd4e0f4e248c8168 X-Google-Attributes: gid103376,public From: Laurent.Guerby@enst-bretagne.fr (Laurent Guerby) Subject: Re: String to Variable Name Mapping Date: 1996/04/13 Message-ID: <4xybo0sb1s.fsf@leibniz.enst-bretagne.fr>#1/1 X-Deja-AN: 147275881 distribution: world sender: guerby@leibniz.enst-bretagne.fr references: <4kjico$emb@newssvr.cacd.rockwell.com> content-type: text/plain; charset=US-ASCII organization: Telecom Bretagne mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-04-13T00:00:00+00:00 List-Id: "F. Britt Snodgrass" writes : : Is there an attribute or some other way to use the contents of a string : variable to point to another variable? : : For example, if I have the following declarations, : : Int_Var : Integer; : Str_Var : String (1..32) := "Int_Var"; : : can I somehow use the contents of Str_Var to make an assignment to : Int_Var? : : I'd like to do this as a way of initializing variables by reading from a : text file containing the variable name and the desired initial value. Ada is not an interpreted language that allow such tricks ;-). Here is a reasonable way of doing something equivalent : -- Laurent Guerby, 13 April 1996. -- Tested and approved by GNAT ;-). with Ada.Text_IO; procedure Symbol is package Text_IO renames Ada.Text_IO; -- with vs use ... ;-). type Variable_Type is new Integer; -- Taken from your example. package Value_IO is new Ada.Text_IO.Integer_IO (Variable_Type); -- Easy value IO. type Variable_Name is (Var_1, Var_2, Var_3); -- Enumeration type. package Name_IO is new Ada.Text_IO.Enumeration_IO (Variable_Name); -- You'll need it for easy IO operations on names. type Table is array (Variable_Name) of Variable_Type; -- If you want different types, it's doable but it'll need -- a bit more work. Symbol_Table : Table; -- The interesting variable ;-). Current_Name : Variable_Name; Current_Value : Variable_Type; begin Name_IO.Get (Current_Name); Value_IO.Get (Current_Value); Symbol_Table (Current_Name) := Current_Value; Text_IO.New_Line (2); Name_IO.Put (Current_Name); Text_IO.Put (" = "); Value_IO.Put (Symbol_table (Current_Name)); Text_IO.New_line; end Symbol; Here is one possible execution : guerby@leibniz:/tmp$ ./symbol var_1 2 VAR_1 = 2 guerby@leibniz:/tmp$ This make (extensive) use of Ada.Text_IO, if you want more precisisons about that, just follow the Lovelace tutorial (from http://lglwww.epfl.ch/Ada/ by David Wheeler) or run to your bookshop and buy an Ada book ;-). Note that we use that in DART with an array of access to Mapping function, to make the link between the scene description file (which uses names) and predefined color mappings (the Symbol_Table is defined at elaboration time with procedures access). If you got a name clash between your enum type and a predefined Ada word, youi've to add a dummy postfix (or prefix) to each name and hack a bit the IO routines. : Thanks, : Britt Snodgrass (mailto:britt@acm.org) Hope this helps, -- -- Laurent Guerby, student at Telecom Bretagne (France), Team Ada -- "Use the Source, Luke. The Source will be with you, always (GPL)" -- http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project) -- Try GNAT, the GNU Ada 95 compiler (ftp://cs.nyu.edu/pub/gnat)