Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
37
Task/Dynamic-variable-names/EMal/dynamic-variable-names.emal
Normal file
37
Task/Dynamic-variable-names/EMal/dynamic-variable-names.emal
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
^|EMal doesn't support the creation of user-defined variable names.
|
||||
|It can manage symbolic references to existing variables.
|
||||
|It can use Records to dynamically create fields.
|
||||
|^
|
||||
Record data ← []
|
||||
fun fillData ← void by block
|
||||
for ever
|
||||
^|we ask for key/value pairs|^
|
||||
text key ← ask(text, "Enter the key or press Enter to quit: ")
|
||||
if key æ Text.EMPTY do break end
|
||||
text value ← ask(text, "Enter the value: ")
|
||||
data[key] ← value ^|here we set the user-defined key field
|
||||
|on the record data, with the provided value
|
||||
|^
|
||||
end
|
||||
writeLine()
|
||||
end
|
||||
^|here we show how symbolic reference works by using var("variableName")|^
|
||||
fun dumpData ← void by text recordName
|
||||
writeLine("dumping the fields for the record named '", recordName, "'")
|
||||
Record.keys(var(recordName)).list(<text key|
|
||||
writeLine(" ", key, " ⇒ ", var(recordName)[key]))
|
||||
end
|
||||
^|
|
||||
|fillData()
|
||||
|dumpData(ask(text, "Enter the name of the variable (must be 'data'): "))
|
||||
|^
|
||||
text recordName
|
||||
if Runtime.args.length æ 3
|
||||
data[Runtime.args[0]] ← Runtime.args[1]
|
||||
recordName ← Runtime.args[2]
|
||||
else
|
||||
fillData()
|
||||
end
|
||||
dumpData(when(recordName æ Text.EMPTY,
|
||||
ask(text, "Enter the name of the variable (must be 'data'): "),
|
||||
recordName))
|
||||
Loading…
Add table
Add a link
Reference in a new issue