1 ;;"tree.scm" Implementation of COMMON LISP tree functions for Scheme
2 ; Copyright 1993, 1994 David Love (d.love@dl.ac.uk)
4 ;Permission to copy this software, to redistribute it, and to use it
5 ;for any purpose is granted, subject to the following restrictions and
8 ;1. Any copy made of this software must include this copyright notice
11 ;2. I have made no warrantee or representation that the operation of
12 ;this software will be error-free, and I am under no obligation to
13 ;provide any services, by way of maintenance, update, or otherwise.
15 ;3. In conjunction with products arising from the use of this
16 ;material, there shall be no use of my name in any advertising,
17 ;promotional, or sales literature without prior written consent in
20 ;; Deep copy of the tree -- new one has all new pairs. (Called
21 ;; tree-copy in Dybvig.)
22 (define (tree:copy-tree tree)
24 (cons (tree:copy-tree (car tree))
25 (tree:copy-tree (cdr tree)))
28 ;; Substitute occurrences of old equal? to new in tree.
29 ;; Similar to tree walks in SICP without the internal define.
30 (define (tree:subst new old tree)
31 (let walk ((tree tree))
32 (cond ((equal? old tree)
35 (cons (walk (car tree))
39 ;; The next 2 aren't in CL. (Names from Dybvig)
41 (define (tree:substq new old tree)
42 (let walk ((tree tree))
46 (cons (walk (car tree))
50 (define (tree:substv new old tree)
51 (let walk ((tree tree))
52 (cond ((eqv? old tree)
55 (cons (walk (car tree))
59 (define copy-tree tree:copy-tree)
60 (define subst tree:subst)
61 (define substq tree:substq)
62 (define substv tree:substv)