summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-06-19 22:18:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-06-19 22:18:26 -0700
commit4bedd6056cc59f7194ae4eede97b4c460275fcc8 (patch)
tree54d510492a8f31d85fbac59b76a28478cee19691 /share
parent9fcc160f06441f187e4a2bf2e39164eb8039b190 (diff)
downloadtxr-4bedd6056cc59f7194ae4eede97b4c460275fcc8.tar.gz
txr-4bedd6056cc59f7194ae4eede97b4c460275fcc8.tar.bz2
txr-4bedd6056cc59f7194ae4eede97b4c460275fcc8.zip
* txr.1: Documented ifa.
* share/txr/stdlib/ifa.tl: Tightened up the tests for situations when the macro is ill-formed, following the improved specification. Also, eval-error is thrown instead of just error.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/ifa.tl16
1 files changed, 12 insertions, 4 deletions
diff --git a/share/txr/stdlib/ifa.tl b/share/txr/stdlib/ifa.tl
index f7c4fcb0..180e5231 100644
--- a/share/txr/stdlib/ifa.tl
+++ b/share/txr/stdlib/ifa.tl
@@ -29,15 +29,23 @@
(cond
((or (atom test) (null (cdr test))) ^(let ((it ,test))
(if it ,then ,else)))
- ((member (first test) '(not null)) ^(ifa ,(second test) ,else ,then))
+ ((member (first test) '(not null false))
+ (unless (eql (length test) 2)
+ (throwf 'eval-error "ifa: wrong number of arguments to ~s"
+ (first test)))
+ ^(ifa ,(second test) ,else ,then))
(t (let* ((sym (first test))
(args (rest test))
(n-candidate-args [count-if candidate-p args])
(pos-candidate (or [pos-if candidate-p args] 0)))
- (unless (fboundp sym)
- (error "ifa: only works with global functions."))
+ (unless (or (lexical-fun-p e sym)
+ (and (or (functionp (symbol-function sym))
+ (null (symbol-function sym)))))
+ (throwf 'eval-error "ifa: test expression must be \
+ \ a simple function call"))
(when (> n-candidate-args 1)
- (error "ifa: ambiguous situation: not clear what can be \"it\"."))
+ (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))