From e1b76996ce822915896408e084695bda4bbcb465 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 12 Jul 2015 07:12:00 -0700 Subject: * share/txr/stdlib/ifa.tl (ifa): Use placelet to allow "it" to be mutable when it denotes a place form. --- ChangeLog | 5 +++++ share/txr/stdlib/ifa.tl | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a4a21d9..d28e85b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-12 Kaz Kylheku + + * share/txr/stdlib/ifa.tl (ifa): Use placelet to + allow "it" to be mutable when it denotes a place form. + 2015-07-12 Kaz Kylheku * share/txr/stdlib/place.tl (place-form-p): New function. diff --git a/share/txr/stdlib/ifa.tl b/share/txr/stdlib/ifa.tl index bffe8246..1f79c208 100644 --- a/share/txr/stdlib/ifa.tl +++ b/share/txr/stdlib/ifa.tl @@ -46,10 +46,21 @@ (when (> n-candidate-args 1) (throwf 'eval-error "ifa: ambiguous situation: \ \ not clear what can be \"it\"")) - (let* ((temps (mapcar (ret (gensym)) args)) - (it-temp [temps pos-candidate])) - ^(let* (,*(zip temps args) (it ,it-temp)) - (if (,sym ,*temps) ,then ,else)))))))) + (iflet ((it-form (macroexpand [args pos-candidate] e)) + (is-place (place-form-p it-form))) + (let ((before-it [args 0..pos-candidate]) + (after-it [args (succ pos-candidate)..:])) + (let* ((btemps (mapcar (ret (gensym) before-it))) + (atemps (mapcar (ret (gensym) after-it)))) + ^(let (,*(zip btemps before-it)) + (placelet ((it ,it-form)) + (let (,*(zip atemps after-it)) + (if (,sym ,*atemps it ,*btemps) + ,then ,else)))))) + (let* ((temps (mapcar (ret (gensym)) args)) + (it-temp [temps pos-candidate])) + ^(let* (,*(zip temps args) (it ,it-temp)) + (if (,sym ,*temps) ,then ,else))))))))) (defmacro conda (. pairs) (tree-case pairs -- cgit v1.2.3