[plt-scheme] question on cond

From: Prabhakar Ragde (plragde at uwaterloo.ca)
Date: Fri Sep 12 09:59:22 EDT 2008

Chongkai Zhu wrote:
> If you have to write cond as a macro in Scheme, what will you write? I 
> will do
> 
> (define-syntax cond
>  (syntax-rules (=> else)
>    ;other cases
>    ((cond (test-expr)
>           cond-clause ...)
>     (or test-expr
>         (cond (cond-clause ...))))))
> 
> So is the `a' in `(or a b)' in tail position as the whole or expression. 
> No it isn't. You will have
> 
> (define-syntax or
>  (syntax-rules ()
>    ((or a b)
>     (let ((t a))
>       (if t t b)))))
> 
> The continuation of `a' need to test whether it is true or not, and then 
> decide the return value of the whole expression.

Thanks. I missed the text further up that said that if the test 
expression evaluates to #f, then the result depends on the rest of the 
cond clauses. I thought it just returned the value of the test 
expression unconditionally. Sorry for the noise. --PR


Posted on the users mailing list.