[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Anaphoric IF
From: |
William Annis |
Subject: |
Re: [Chicken-users] Anaphoric IF |
Date: |
Mon, 24 Nov 2003 07:18:54 -0600 (CST) |
>(if* (member x y) (cadr it) ...)
>
>(if* (assq x y) (cdr it) #f)
>
<snip>
>
>Pointless or practical?
I do this all the time.
;; Anaphoric varieties of these things.
(define-macro (if* test a-then a-else)
`(let ((it ,test))
(if it ,a-then ,a-else)))
;; Translated from "On Lisp" version by Paul Graham.
(define-macro (cond* . clauses)
(if (null? clauses)
#f
(let ((cl1 (car clauses))
(sym (gensym)))
`(let ((,sym ,(car cl1)))
(if ,sym
(let ((it ,sym)) ,@(cdr cl1))
(cond* ,@(cdr clauses)))))))
--
William Annis - System Administrator - Biomedical Computing Group
"No man forgets his original trade: the rights of nations and of kings sink
into questions of grammar, if grammarians discuss them." Samuel Johnson