Advertisement
PonaFly

Untitled

Mar 24th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.67 KB | None | 0 0
  1. (define (addword word tree)
  2.  (define (help code tree)
  3.    (if (empty? code) (car word)
  4.     (if (=(car code) 0)
  5.         (if (left tree)
  6.       (cons (help (cdr code) (left tree)) (right tree))
  7.        +inf.0)
  8.        (if (right tree)
  9.       (cons (left tree) (help (cdr code) (right tree)))
  10.        +inf.0
  11.         ))))
  12.   (help (cdr word) tree))
  13. (define (left tree)
  14.   (if (empty? tree) '()
  15.       (if (not(pair? tree)) false
  16.       (car tree))))
  17. (define (right tree)  
  18.   (if (empty? tree) '()
  19.     (if (not(pair? tree)) false
  20.       (cdr tree))))
  21. (define (main lst)
  22.  (foldl addword '() lst))
  23.  
  24. (define (decode? lst)
  25. (if (member +inf.0 (flatten (main lst))) false true))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement