summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-10-26 07:46:17 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-10-26 07:46:17 -0700
commitbf96924d0781b62ea447a01e9bc7a395f0bf609d (patch)
treed960eca68c0793c1443f62d4cd7b49d6a9cee164
parent64e0f2c2f3fb9c543f247fb65172fc4690018bbc (diff)
downloadtxr-bf96924d0781b62ea447a01e9bc7a395f0bf609d.tar.gz
txr-bf96924d0781b62ea447a01e9bc7a395f0bf609d.tar.bz2
txr-bf96924d0781b62ea447a01e9bc7a395f0bf609d.zip
ifa: take advantage of read-once.
* stdlib/ifa.tl (ifa): When the form bound to the it anaphoric variable is a place, such that we use placelet, wrap the place in (read-once ...) so that multiple evaluations of it don't cause multiple accesses of the place. * txr.1: Documented.
-rw-r--r--stdlib/ifa.tl2
-rw-r--r--txr.18
2 files changed, 8 insertions, 2 deletions
diff --git a/stdlib/ifa.tl b/stdlib/ifa.tl
index eaab6f3a..317ef9e7 100644
--- a/stdlib/ifa.tl
+++ b/stdlib/ifa.tl
@@ -54,7 +54,7 @@
(let* ((btemps (mapcar (ret (gensym)) before-it))
(atemps (mapcar (ret (gensym)) after-it)))
^(let (,*(zip btemps before-it))
- (placelet ((it ,it-form))
+ (placelet ((it (read-once ,it-form)))
(let (,*(zip atemps after-it))
(if (,sym ,*(if (eq 'dwim sym) ^(,(second test)))
,*btemps it ,*atemps)
diff --git a/txr.1 b/txr.1
index 66df2a59..e41b36ff 100644
--- a/txr.1
+++ b/txr.1
@@ -16915,7 +16915,13 @@ alias is used multiple times in the
.meta then
or
.meta else
-expressions. Otherwise, if the form is not a syntactic place
+expressions. Furthermore, the place form is implicitly surrounded with
+.code read-once
+so that the place's value is accessed only once, and multiple references to
+.code it
+refer to a copy of the value cached in a hidden variable, rather than
+generating multiple accesses to the place.
+Otherwise, if the form is not a syntactic place
.code it
is bound as an ordinary lexical variable to
the form's value.