[plt-scheme] HtDP ex 11.2.4

From: Richard Cleis (rcleis at mac.com)
Date: Sat Feb 18 03:33:55 EST 2006

> Another completely equivalent way is:
>
> (define (list-template a-list)
>   (cond
>     [(empty? a-list) ...]
>     [(cons? a-list) ...]))
>
> If you wanted to be creative, you could then switch the order of the
> clauses, and then even replace the (empty? a-list) with "else".

It is creativity that gives me pause.  If I deviate from the templates 
to do something like this:

(define (depth dl)
   (cond ((cons? dl) (+ 1 (depth (first dl))))
         (else 0)))

then am I tempting smite from tail recursion gods, or is this 
acceptable?  It is sometimes difficult to distinguish whether a 
practice is intended to improve programming or is intended to improve 
the operation of the language.

rac



Posted on the users mailing list.