[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Don't use => in COND...



You can always redefine COND so that it expands into something
that's more efficient for the interpreter (and perhaps a little
less efficient for the compiler).  For example:

(define-syntax (cond . clauses)
  (iterate loop ((clauses clauses))
    (if (null? clauses)
        '**no-more-cond-clauses**
        (let ((first (car clauses))
              (rest (loop (cdr clauses))))
          (if (eq? (cadr first) '=>)
              (destructure (((pred () proc) first)
                            (p (generate-symbol 'p)))
                `(let ((,p ,pred)) (if ,p (,proc ,p) ,rest)))
              (destructure (((pred . things) first))
                (cond ((null? things) `(or ,pred ,rest))
                      ((null? (cdr things)) `(if ,pred ,(car things) ,rest))
                      (else `(if ,pred (block ,@things) ,rest)))))))))