Skip to content

Commit

Permalink
Make value in MAKE-VARIABLE optional
Browse files Browse the repository at this point in the history
To match DEFVAR.
  • Loading branch information
Bike committed Oct 7, 2023
1 parent d6e6465 commit 217671e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Code/clostrum.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
(define-accessor env:symbol-value (client environment variable-name))
(defgeneric env:boundp (client env variable-name))
(defgeneric env:makunbound (client env variable-name))
(defgeneric env:make-variable (client environment variable-name value))
(defgeneric env:make-variable (client environment variable-name
&optional value))
(defgeneric env:make-parameter (client environment variable-name value))
(defgeneric env:make-constant (client environment variable-name value))
(defgeneric env:make-symbol-macro (client environment variable-name expansion))
Expand Down
20 changes: 11 additions & 9 deletions Code/default-methods.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@
(sys:variable-cell-makunbound
client (sys:variable-cell client environment variable-name)))

(defmethod env:make-variable (client environment variable-name new)
(defmethod env:make-variable (client environment variable-name
&optional (value nil valuep))
(ecase (sys:variable-status client environment variable-name)
((nil)
(setf (sys:variable-cell-value
client (sys:variable-cell client environment variable-name))
new
(sys:variable-status client environment variable-name)
:special))
(when valuep
(setf (sys:variable-cell-value
client (sys:variable-cell client environment variable-name))
value))
(setf (sys:variable-status client environment variable-name) :special))
((:special)
(let ((cell (sys:variable-cell client environment variable-name)))
(unless (sys:variable-cell-boundp client cell)
(setf (sys:variable-cell-value client cell) new))))
(when valuep
(let ((cell (sys:variable-cell client environment variable-name)))
(unless (sys:variable-cell-boundp client cell)
(setf (sys:variable-cell-value client cell) value)))))
((:constant)
(error 'env:attempt-to-define-special-variable-for-existing-constant
:name variable-name))
Expand Down
2 changes: 1 addition & 1 deletion Code/documentation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ The nature of a setf expander is otherwise implementation-defined. One choice wo
(function env:makunbound
"As CL:MAKUNBOUND. Make VARIABLE-NAME have no global value in ENVIRONMENT. Returns VARIABLE-NAME.")
(function env:make-variable
"Functional version of CL:DEFVAR. Proclaim VARIABLE-NAME special, and if it has no global value, set its global value to VALUE.")
"Functional version of CL:DEFVAR. Proclaim VARIABLE-NAME special, and if it has no global value and VALUE is provided, set its global value to VALUE.")
(function env:make-parameter
"Functional version of CL:DEFPARAMETER. Proclaim VARiABLE-NAME special, and set its global value to VALUE.")
(function env:make-constant
Expand Down

0 comments on commit 217671e

Please sign in to comment.