Specifies the variables initially bound in a new process.
mp
A list of bindings that are needed by LispWorks.
The variable *process-initial-bindings*
specifies the variables that are initially bound in a Lisp process when that process is created. This variable is an association list of symbols and initial value forms. The initial value forms are processed by a simple evaluation that handles symbols and function call forms, but not special operators.As a special case, if the value form is the same as the symbol and that symbol is unbound, then the symbol will be unbound in the new process.
When process-run-function is called, it performs the evaluation in the dynamic environment of the call. It is therefore possible to bind *process-initial-bindings*
dynamically around the call, as shown in the examples below, and that is the preferred way of using *process-initial-bindings*
(rather than setting the global value).
The initial value forms in *process-initial-bindings*
are also evaluated in outer calls on foreign threads, which are threads that were made by foreign code rather than by Lisp. See 19.12.1 Foreign callbacks on threads not created by Lisp for discussion. Note that in this case. the evaluation occurs in a dynamic environment where the variables in *process-initial-bindings*
are not bound yet. That is different from calls to process-run-function, where all the variables that were in *process-initial-bindings*
at the time that the calling process was created are already bound.
Changing the global value of *process-initial-bindings*
affects all new processes in the system, including processes that will be associated with foreign threads. Unless that is what you want, you should not set the global value. When you do set it, you should take care to avoid errors.
Errors in the evaluation are signaled in the standard way when they occur due to to process-run-function. When LispWorks creates processes for its own use, it just ignores such errors and binds the corresponding variable to nil
. When the evaluation is for a foreign thread, the error is signaled as usual, wrapped with a restart that allows you to use nil
as the value.
This example shows a typical use with a bound symbol:
(defvar *binding-1* 10)
(let ((mp:*process-initial-bindings* (cons '(*binding-1* . 20) mp:*process-initial-bindings*))) (mp:process-run-function "binding-1" '() #'(lambda (stream) (format stream "~&Binding 1 is ~S.~%" *binding-1*)) *standard-output*) (sleep 1)) => Binding 1 is 20.
This example shows the special case with an unbound symbol:
(defvar *binding-2*)
(let ((mp:*process-initial-bindings* (cons '(*binding-2* . *binding-2*) mp:*process-initial-bindings*))) (flet ((check-binding-2 () (mp:process-run-function "binding-2" '() #'(lambda (stream) (if (boundp '*binding-2*) (format stream "~&Binding 2 is ~S.~%" *binding-2*) (format stream "~&Binding 2 is unbound.~%"))) *standard-output*) (sleep 1))) (check-binding-2) (let ((*binding-2* 123)) (check-binding-2)))) => Binding 2 is unbound. Binding 2 is 123.
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:51