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.


import "io" for Stdin, Stdout
 
var userVars = {}
System.print("Enter three variables:")
for (i in 0..2) {
    System.write("\n  name : ")
    Stdout.flush()
    var name = Stdin.readLine()
    System.write("  value: ")
    Stdout.flush()
    var value = Num.fromString(Stdin.readLine())
    userVars[name] = value
}
 
System.print("\nYour variables are:\n")
for (kv in userVars) {
    System.print("  %(kv.key) = %(kv.value)")
}