Task

Create a variable with a user-defined name.

The variable name should not be written in the program text, but should be taken from the user dynamically.



See also
   Eval in environment is a similar task.


var name = read("Enter a variable name: ", String);     # type in 'foo'
 
class DynamicVar(name, value) {
    method init {
        DynamicVar.def_method(name, ->(_) { value })
    }
}
 
var v = DynamicVar(name, 42);       # creates a dynamic variable
say v.foo;                          # retrieves the value