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.


constant globals = new_dict()
 
while 1 do
    string name = prompt_string("Enter name or press Enter to quit:")
    if length(name)=0 then exit end if
    bool bExists = (getd_index(name,globals)!=NULL)
    string prompt = iff(not bExists?"No such name, enter a value:"
                   :sprintf("Already exists, new value[%s]:",{getd(name,globals)}))
    string data = prompt_string(prompt)
    if length(data) then
        setd(name,data,globals)
    end if
end while