[plt-scheme] Tree recursion

From: Jos Koot (jos.koot at telefonica.net)
Date: Wed Jan 23 08:55:37 EST 2008

After exchanging car and cdr:
(define reverse-tree-copy
  (lambda (tr)
    (if (not (pair? tr))
        tr
        (cons (tree-copy (cdr tr))
              (tree-copy (car tr))))))

(reverse-tree-copy '((a . b) . c)) ; --> (c b . a) = (c . (b . a))

Reversed-tree-copy returns every pair reversed. If you insert all dots and 
parentheses of all pairs you will find that the result is the same as the 
input, but in reverse order. In DrScheme you can use the language menu for 
constructor style output. That may clarify things too.
Jos

----- Original Message ----- 
From: "Grant Rettke" <grettke at acm.org>
To: "pltscheme" <plt-scheme at list.cs.brown.edu>
Sent: Wednesday, January 23, 2008 4:11 AM
Subject: [plt-scheme] Tree recursion


> Hi folks,
>
> I am working on problem 2.8.1 in TSPL:
> http://www.scheme.com/tspl3/start.html#./start:h8
>
> I am having a tough time visualizing this. I tried tracing it and
> drawing it out on paper. What makes me think I don't understand this
> well enough is that the answer is not obvious to me.
>
> At risk of this being a dumb question, is there a good way to go about
> understanding/visualizing this kind of recursion other than what I am
> already doing?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 



Posted on the users mailing list.