[gambit-list] Parameter objects performance Q

Adam adam.mlmb at gmail.com
Mon Mar 9 00:56:52 EDT 2020


For completeness, I asked a Common Lisper about CL dynamic variables. Here
is how CL dynamic variables work:

 * In CL, all global variables are "dynamic", and they're defined using
|defvar|.

 * By convention their names are prefixed and suffixed by stars, which is
not required by the language.

 * In the place of Scheme |parameterize|, CL uses ordinary |let|.

   I.e., CL |let| when binding the name of a global variable means
|parameterize|, and otherwise means |let|.

 * In the place of the procedure call as accessor ("(myparam)"), CL uses
normal variable load ("myparam").

 * I wildguess a condition that makes it easier for CL to accommodate this
syntax without incredible overhead, is the fact that they do not have first
class continuations (but only escape continuations which mean N-step
procedure return), so they don't have the question "which dynamic variable
assignment should apply in which continuation".

   He also confirmed that in CL, |let| of a dynamic variable, *implies
backup of the variable's previous value, and at return time, restore of the
variable to that previous value*. This restore is carried out also in case
of "abnormal termination", example: (tagbody (let ((*v* 234)) (go a)) a) or
(tagbody (let ((*v* 234)) (print "hello") (go a) (print "hi")) a), go means
non-local control transfer (goto).


Example 1, prints out "123":
(defvar *v*) ; <- Define dynamic variable ()
(defun a ()
  (let ((*v* 123)) ; <- Note, let on a dynamic variable means |parameterize|
    (b)))
(defun b () (c))
(defun c () (print *v*)) ; <- Use, same syntax as normal variable access.


Example 2, prints out "123234":
(defvar *v*) ; <- Define dynamic variable ()
(defun a ()
  (let ((*v* 123)) ; <- Note, let on a dynamic variable means |parameterize|
    (d)
    (b)))
(defun b ()
  (let ((*v* 234))
    (c)))
(defun c () (d))
(defun d () (print *v*)) ; <- Use, same syntax as normal variable access.


Reference is the "Common Lisp HyperSpec" produced by LispWorks:
http://www.lispworks.com/reference/HyperSpec/Body/03_abaab.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20200309/a3e2f880/attachment.htm>


More information about the Gambit-list mailing list