summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-12-09 06:49:32 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-12-09 06:49:32 -0800
commit602555a3178f8fa46ef68d162509717dc82ed1c0 (patch)
treeb39bbe6f848dce7421fb5282a1dd6c05c8d44f57 /share
parent632acffb331db8674aded94425ed87b44e501058 (diff)
downloadtxr-602555a3178f8fa46ef68d162509717dc82ed1c0.tar.gz
txr-602555a3178f8fa46ef68d162509717dc82ed1c0.tar.bz2
txr-602555a3178f8fa46ef68d162509717dc82ed1c0.zip
Bugfix: ifa must allow dwim expressions.
* share/txr/stdlib/ifa.tl (ifa): Accept dwim expressions as the condition. Moreover, treat [f x] as a one-argument call, even though it is the two-argument form (dwim f x). * txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/ifa.tl9
1 files changed, 6 insertions, 3 deletions
diff --git a/share/txr/stdlib/ifa.tl b/share/txr/stdlib/ifa.tl
index aa406bbd..cefb38eb 100644
--- a/share/txr/stdlib/ifa.tl
+++ b/share/txr/stdlib/ifa.tl
@@ -35,11 +35,12 @@
(first test)))
^(ifa ,(second test) ,else ,then))
(t (let* ((sym (first test))
- (args (rest test))
+ (args (if (eq 'dwim sym) (cddr test) (cdr test)))
(n-candidate-args [count-if candidate-p args])
(pos-candidate (or [pos-if candidate-p args] 0)))
(unless (or (lexical-fun-p e sym)
(and (or (functionp (symbol-function sym))
+ (eq sym 'dwim)
(null (symbol-function sym)))))
(throwf 'eval-error "ifa: test expression must be \
\ a simple function call"))
@@ -55,12 +56,14 @@
^(let (,*(zip btemps before-it))
(placelet ((it ,it-form))
(let (,*(zip atemps after-it))
- (if (,sym ,*btemps it ,*atemps)
+ (if (,sym ,*(if (eq 'dwim sym) ^(,(second test)))
+ ,*btemps it ,*atemps)
,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)))))))))
+ (if (,sym ,*(if (eq 'dwim sym) ^(,(second test)))
+ ,*temps) ,then ,else)))))))))
(defmacro conda (. pairs)
(tree-case pairs