-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_68.el
20 lines (17 loc) · 804 Bytes
/
2_68.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(load-file "2_67.el")
(defun contains? (list element)
(cond ((not list) nil)
((equal element (car list)) t)
(t (contains? (cdr list) element))))
(defun encode-symbol (symbol tree)
(defun present-in-branch? (branch-selector) (contains? (symbols (funcall branch-selector tree)) symbol))
(defun rest-bits-from (branch-selector) (encode-symbol symbol (funcall branch-selector tree)))
(cond ((leaf? tree) nil)
((present-in-branch? #'left-branch) (cons 0 (rest-bits-from #'left-branch)))
((present-in-branch? #'right-branch) (cons 1 (rest-bits-from #'right-branch)))
(t (error "No such symbol in table"))))
(defun encode (message tree)
(if (not message)
'()
(append (encode-symbol (car message) tree)
(encode (cdr message) tree))))