问题
I am trying to build a function that encodes the following procedure at the bottom into 1's and 0's can anyone help find why I am getting the error message mpair given: 0.
(define (symbols tree)
(if (leaf? tree)
(list (symbol-leaf tree))
(caddr tree)))
(define (right-branch tree) (cadr tree))
(define (left-branch tree) (car tree))
(define (leaf? object)
(eq? (car object) 'leaf))
(define (member? x set)
(not (equal? (member x set) false)))
(define (encode-branch symbol tree)
(let ((left (left-branch tree))
(right (right-branch tree)))
(cond ((member? symbol (symbols left)) (list 0 left))
((member? symbol (symbols right)) (list 1 right))
(else (error symbol tree)))))
(define (encode symbol tree)
(if (leaf? tree) '()
(let ((new-branch (encode-branch symbol tree)))
(cons (car new-branch) (encode symbol (cadr new-branch))))))
(encode "doo doo doo da da da da" '((da . 00) (doo . 01) (ron . 1)))
来源:https://stackoverflow.com/questions/47149369/encode-huffman-tree-scheme