Hi
Suppose string variable strVar has value "fooVar".
fooVar is a valid variable name used elsewhere in the program.
How does one obtain from strVar:
- The type of fooVar;
- The value of fooVar?
Best regards
Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
October 16, 2021 Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Hi Suppose string variable strVar has value "fooVar". How does one obtain from strVar:
Best regards |
October 16, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to DLearner | On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: >How does one obtain from strVar:
|
October 16, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote: >On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: >How does one obtain from strVar:
Failed with 2x "Error: variable |
October 17, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to DLearner | On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: >On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote: >On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: >How does one obtain from strVar:
Failed with 2x "Error: variable I don't know how to do it with a string, but are you willing to do it with an
|
October 17, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to DLearner | On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: >
Failed with 2x "Error: variable You can fix this by making
|
October 17, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 17 October 2021 at 02:31:04 UTC, Paul Backus wrote: >On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: >
Failed with 2x "Error: variable You can fix this by making
Doesn't solve the compile-time only problem though :( |
October 17, 2021 Re: Obtaining type and value of a variable named in another variable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tejas | On Sunday, 17 October 2021 at 02:42:54 UTC, Tejas wrote: >Doesn't solve the compile-time only problem though :( Well, the fundamental issue is that in a language like D that compiles to machine code, variable names only exist at compile time. At runtime, the only thing you have is memory addresses (pointers). If you want to look something up by name at runtime, you will have to use a data structure like an associative array:
Of course, in this example, the associative array can only store |