; Various versions of in-tree that I did not like.
(define in-tree-1?
(lambda (symbol tree-of-symbols)
(if (not (pair? tree-of-symbols))
(equal? tree-of-symbols symbol)
(or (letrec ((branch-test
(lambda (branch)
(if (not (pair? branch))
(equal? symbol branch)
(if (pair? (car branch))
(branch-test (car branch))
(or (equal? (car branch) symbol)
(branch-test (cdr branch))))))))
(branch-test (car tree-of-symbols)))
(in-tree-1? symbol (cdr tree-of-symbols))))))
; Test with (in-tree-1? 'a (cons (cons (cons 'b null) 'a) null))
(define in-tree-2?
(lambda (symbol tree-of-symbols)
(if (not (pair? tree-of-symbols))
(eq? symbol tree-of-symbols)
(let ((left (equal? symbol (car tree-of-symbols)))
(right (in-tree-2? symbol (cdr tree-of-symbols))))
(or left right)))))
; Test with (in-tree-2? 'a (cons (cons 'a 'b) null))
(define in-tree-3?
(lambda (symbol tree-of-symbols)
(if (not (pair? tree-of-symbols))
(eq? symbol tree-of-symbols)
(let ((left (in-tree-3? symbol (car tree-of-symbols)))
(right (in-tree-3? symbol (cdr tree-of-symbols))))
(or left right)))))
; Inefficient to look at both subtrees
(define in-tree-4?
(lambda (symbol tree-of-symbols)
(if (not (pair? tree-of-symbols))
(eq? symbol tree-of-symbols)
(or (in-tree-4? symbol (car tree-of-symbols))
(in-tree-4? symbol (cdr tree-of-symbols))))))