From bf96924d0781b62ea447a01e9bc7a395f0bf609d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 26 Oct 2021 07:46:17 -0700 Subject: 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. --- stdlib/ifa.tl | 2 +- txr.1 | 8 +++++++- 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. -- cgit v1.2.3