[plt-scheme] question on cond

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Fri Sep 12 09:47:24 EDT 2008

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.


Prabhakar Ragde wrote:
> I have a student working in the EOPL language level who submitted 
> programs whose cond expressions do not contain the else keyword. It 
> isn't replaced by #t; it just isn't there. Having drunk deeply of HtDP 
> Kool-Aid, I was not aware that a cond clause could be of the form 
> [test-expr]. But the PLT Scheme Reference, section 2.12, says that 
> test-expr is not in tail position with respect to the cond form. Why 
> not? --PR
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.