;;;;;; Extended COND macro -*- Scheme -*- ;;; Taylor Campbell wrote this code; he places it in the public domain. ;;; An extended COND macro. This not only supports the => clause, but ;;; also an extended => clause for more sophisticated testing & binding ;;; of results. It also allows internal definitions in clauses. ;;; For example, ;;; (COND* ((READ-CHAR ) NOT-EOF-OBJECT? ;;; => (LAMBDA () ..char..)) ;;; (ELSE ..eof..)) ;;; as opposed to ;;; (LET (( (READ-CHAR ))) ;;; (IF (EOF-OBJECT? ) ;;; ..char.. ;;; ..eof..)) ;;; Note that, although they're about equal in length, the COND* one ;;; may be linearly nested. (define-syntax cond* (syntax-rules (=> ELSE) ((COND* (ELSE else1 else2 ...)) (LET () else1 else2 ...)) ((COND* (test => receiver) more-clause ...) (LET ((T test)) (COND*/MAYBE-MORE T (receiver T) more-clause ...))) ((COND* (test predicate => receiver) more-clause ...) (CALL-WITH-VALUES (LAMBDA () test) (LAMBDA T (COND*/MAYBE-MORE (APPLY predicate T) (APPLY receiver T) more-clause ...)))) ((COND* (test) more-clause ...) (LET ((T test)) (COND*/MAYBE-MORE T T more-clause ...))) ((COND* (test body1 body2 ...) more-clause ...) (COND*/MAYBE-MORE test (LET () body1 body2 ...) more-clause ...)))) (define-syntax cond*/maybe-more (syntax-rules () ((COND*/MAYBE-MORE test con) (IF test con)) ((COND*/MAYBE-MORE test con clause ...) (IF test con (COND* clause ...)))))