From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Newbie question # 2 Date: Thu, 6 Aug 2020 22:20:11 +0300 Organization: Tidorum Ltd Message-ID: References: <8b2858e0-e69c-4a22-ad51-a6a7c51e7a7do@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net nQClPoSq+xibCpicm+dmUQoP/Yt9yE9yBGrwy8GdLRh9yLqc1B Cancel-Lock: sha1:CjyrcffOLtb1K4OGwKlhEblC8ag= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <8b2858e0-e69c-4a22-ad51-a6a7c51e7a7do@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:59675 List-Id: On 2020-08-06 21:40, Ian Douglas wrote: > Hi all > > I did try Google search and assorted books but could not find > answer. > > In PHP, let's say we have a variable $fruit which contains the string > "banana". > > In PHP, if I do $$fruit, then it creates a variable $banana, which I > can then do things with. Fortran has a similar feature, NAMELIST, for reading values into variables also named in the input. It can also be used for output. Ada does not have such a feature. > Does Ada support any such concept of taking the contents of one > variable and using THAT as a variable? The closest thing in Ada is a variable of an access type, which can be set to refer to some other variable. However, access types do not work with the variable's (string) identifier, but use its run-time memory address (the 'Access attribute). > I'm reading in a file which has a name of an object followed by some > properties so I want to use the name as a variable ... File is > something I created, so it's not some random stuff, and the variables > will be existing already. In Ada, you, yourself, have to program the mapping from the name (string) to the variable. This can be as simple as an if-then-else cascade: if Name = "foo" then Set_Properties (foo); -- Where "foo" is the identifier of a variable. elsif Name = "bar" then Set_Properties (bar); ... end if; Alternatively, you can implement the mapping with a map container from the Ada container library, as Simon Wright suggested. However, if the variables already exist and are used directly in various parts of your program, you may want to store, in the map, /accesses/ to the existing variables, instead of using the map's elements themselves as these variables. -- Niklas Holsti niklas holsti tidorum fi . @ .