; A simple binary tree with numbers: (import scheme (chicken base) (chicken format) (chicken string) datatype test) (define-datatype tree tree? (leaf (n number?)) (branch (left tree?) (right tree?)) ) (define t (branch (branch (leaf 33) (leaf 44)) (leaf 55))) (define (listify t) (cases tree t (leaf (n) n) (branch (left right) (cons (listify left) (listify right))) ) ) (test "listify" '((33 . 44) . 55) (listify t)) (define-record-printer (tree x out) (cases tree x (leaf (n) (fprintf out "~A" n)) (branch (left right) (fprintf out "(~A . ~A)" left right)))) (test "to string" "((33 . 44) . 55)" (->string t)) (test-exit)