2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,5 +1,11 @@
|
|||
{{omit from|Lily}}
|
||||
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.
|
||||
|
||||
;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.
|
||||
* [[Eval in environment]] is a similar task.
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,2 @@
|
|||
(defun rc-create-variable (name initial-value)
|
||||
"Create a global variable whose name is NAME in the current package and which is bound to INITIAL-VALUE."
|
||||
(let ((symbol (intern name)))
|
||||
(proclaim `(special ,symbol))
|
||||
(setf (symbol-value symbol) initial-value)
|
||||
symbol))
|
||||
(setq var-name (read)) ; reads a name into var-name
|
||||
(set var-name 1) ; assigns the value 1 to a variable named as entered by the user
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
CL-USER> (rc-create-variable "GREETING" "hello")
|
||||
GREETING
|
||||
|
||||
CL-USER> (print greeting)
|
||||
"hello"
|
||||
(defun rc-create-variable (name initial-value)
|
||||
"Create a global variable whose name is NAME in the current package and which is bound to INITIAL-VALUE."
|
||||
(let ((symbol (intern name)))
|
||||
(proclaim `(special ,symbol))
|
||||
(setf (symbol-value symbol) initial-value)
|
||||
symbol))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
CL-USER> (rc-create-variable "GREETING" "hello")
|
||||
GREETING
|
||||
|
||||
CL-USER> (print greeting)
|
||||
"hello"
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#import system.
|
||||
#import system'dynamic.
|
||||
#import extensions.
|
||||
|
||||
#class TestClass
|
||||
{
|
||||
#field theVariables.
|
||||
|
||||
#constructor new
|
||||
[
|
||||
theVariables := DynamicStruct new.
|
||||
]
|
||||
|
||||
#method eval
|
||||
[
|
||||
#var(type:subject) varRef := Signature new &literal:(console write:"Enter the variable name:" readLine).
|
||||
theVariables::varRef set:42.
|
||||
|
||||
#var v := theVariables::varRef get.
|
||||
|
||||
console writeLine:(varRef name):"=":(theVariables::varRef get).
|
||||
]
|
||||
}
|
||||
|
||||
#symbol program = TestClass new.
|
||||
|
|
@ -1 +1,4 @@
|
|||
(userDefined)=: 0
|
||||
userDefined=: 'BAR'
|
||||
(userDefined)=: 1
|
||||
BAR
|
||||
1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue