Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:42:54 UTC, Tejas wrote: Doesn't solve the compile-time only problem though :( The only solution I can think of is something with `variant`s, but it'll be messy. Well, the fundamental issue is that in a language like D that compiles to machine code, variable n

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Tejas via Digitalmars-d-learn
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: ```d void main() { import std.stdio; int fooVar = 4; string strVar; strVar = "fooVar"; writeln(typeof(mixin(strVar))); writeln(mixin(strVar)); } ```

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 October 2021 at 23:07:22 UTC, DLearner wrote: ```d void main() { import std.stdio; int fooVar = 4; string strVar; strVar = "fooVar"; writeln(typeof(mixin(strVar))); writeln(mixin(strVar)); } ``` Failed with 2x "Error: variable `strVar` cannot be read at comp

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Tejas via Digitalmars-d-learn
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: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
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: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)` ``` void main() { import std.stdio; int

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)`

Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
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: 1. The type of fooVar; 2. The value of fooVar? Best regards