;;; Procedure: ;;; tree->code ;;; Parameters: ;;; tree, a tree (or tree-like structure) ;;; Purpose: ;;; Build a list that resembles the code to construct the tree. ;;; Produces: ;;; code, a list ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; If you evaluate code, you get tree ;;; Practica: ;;; > (tree->code (cons 'a 'b)) ;;; '(cons a b) ;;; > (tree->code '(a . b)) ;;; '(cons a b) ;;; > (tree->code '((a . b) c . d)) ;;; '(cons (cons a b) (cons c d)) ;;; > (tree->code (list 'a 'b 'c 'd)) ;;; '(cons a (cons b (cons c (cons d null)))) (define tree->code (lambda (tree) (cond [(null? tree) 'null] [(pair? tree) (list 'cons (tree->code (car tree)) (tree->code (cdr tree)))] [else tree])))