diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-05-15 07:41:19 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-05-15 07:41:19 -0700 |
commit | c606261b92348ef7b0f934705ee46ee4ccf28bab (patch) | |
tree | 384d5448080b423bf4ff72b455eb368176f74edb /txr.1 | |
parent | a500d048021a018800ed28f23509800f6b45bf6f (diff) | |
download | txr-c606261b92348ef7b0f934705ee46ee4ccf28bab.tar.gz txr-c606261b92348ef7b0f934705ee46ee4ccf28bab.tar.bz2 txr-c606261b92348ef7b0f934705ee46ee4ccf28bab.zip |
New special operator: progv
Adding a progv operator, similar to the Common Lisp one.
* eval.c (progv_s): New symbol variable.
(op_progv): New static function.
(do_expand): Recognize and traverse the progv form.
(rt_progv): New static function: run-time support
for compiled progv.
(eval_init): Initialize progv_s, and register the the
op_progv operator interpreting function.
* stdlib/compilert (compiler compile): Handle progv
operator ...
(compiler comp-progv): ... via this new method.
* tests/019/progv.tl: New file.
* txr.1: Documented.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -15060,6 +15060,68 @@ closures, but are captured in delimited continuations. (let (:a nil)) -> error, :a and nil can't be used as variables .brev +.coNP Operator @ progv +.synb +.mets (progv < symbols-expr < values-expr << body-form *) +.syne +.desc +The +.code progv +operator binds dynamic variables, and evaluates the +.metn body-form s +in the dynamic scope of those bindings. The bindings are removed +when the form terminates. The result value is that of the +last +.meta body-form +or else +.code nil +if there are no forms. + +The +.meta symbols-expr +and +.meta values-expr +are expressions which are evaluated. Their values are expected +to be lists, of bindable symbols and arbitrary values, respectively. +The symbols coming from one list are bound to the values coming +from the other list. + +If there are more symbols than values, then the extra symbols +will appear unbound, as if they were first bound and then hidden +using the +.code makunbound +function. + +If there are more values than symbols, the extra values are ignored. + +Note that dynamic binding takes place for the symbols even if they +have not been introduced as special variables via +.code defvar +or +.codn defparm . +However, if those symbols appear as expressions denoting variables inside the +.metn body-form s, +they will not necessarily be treated as dynamic variables. +If they have lexical definitions in scope, those will be referenced. +Furthermore, the compiler treats undefined variables as global +references, and not dynamic. + +.TP* Examples: + +.verb + + (progv '(a b) '(1 2) (cons a b)) -> (1 . 2) + + (progv '(x) '(1) (let ((x 4)) (symbol-value 'x))) -> 1 + + (let ((x 'lexical) + (vars (list 'x)) + (vals (list 'dynamic))) + (progv vars vals (list x (symbol-value 'x)))) + + --> (lexical dynamic) +.brev + .SS* Functions .coNP Operator @ defun .synb |