(if (test?)
    (sequence (display "O.K.")
              (ok)
              #T)
    #F)


(define (vypis s)
  (cond ((null? s) (display "[ ]"))
        ((atom? s) (display s))
        (else (display "[ ")
              (vypis (car s))
              (vypis2 (cdr s))
	      (display " ]"))))
(define (vypis2 zoz)
  (cond ((null? zoz) #T)
        ((atom? zoz) (display " . ")
                     (display zoz))
        (else (display " ")
              (vypis (car s))
              (vypis2 (cdr s)))))


(define (ul-in? x ulist)
  (member x ulist))


(define (ul-insert x ulist)
  (cons x ulist))


(define (ul-intersection ulist1 ulist2)
  (cond ((null? ulist1) '())
        ((in? (car ulist1) ulist2)
	 (cons (car ulist1) (ul-intersection (cdr ulist1) ulist2)))
	(else (ul-intersection (cdr ulist1) ulist2))))


(define (ol-in? x olist)
  (member x olist))


(define (ol-insert x olist)
  (cond ((null? olist) (list x))
        ((< x (car olist)) (cons x olist))
        ((= x (car olist)) olist)
	(else (cons (car olist) (ol-insert x (cdr olist))))))


(define (ol-intersection olist1 olist2)
  (cond ((or (null? olist1) (null? olist2)) '())
        ((= (car olist1) (car olist2)) 
           (cons (car olist1) (ol-intersection (cdr olist1) (cdr olist2))))
        ((< (car olist1) (car olist2)) (ol-intersection (cdr olist1) olist2))
        (else (ol-intersection olist1 (cdr olist2)))))


(define (bt-in? x tree)
  (cond ((empty? tree) #F)
        ((= x (value tree)) #T)
        ((< x (value tree)) (bt-in? x (left tree)))
	(else (bt-in? x (right tree)))))


(define (bt-insert x tree)
  (cond ((empty? tree) (make-tree x (empty-tree) (empty-tree)))
        ((= x (value tree)) tree)
        ((< x (value tree)) 
           (make-tree (value tree) (bt-insert x (left tree)) (right tree)))
        (else (make-tree (value tree) (left tree) (insert x (right tree))))))


(define (bt-intersection tree1 tree2)
  (define (pom tree1 a)
    (cond ((empty? tree1) a)
          ((in? (value tree1) tree2) 
             (pom (left tree1) (pom (right tree1)
	                            (bt-insert (value tree1) a))))
          (else (pom (left tree1) (pom (right tree1))))))
  (pom tree1 (empty-tree)))


(define (generate dictionary)
  (define (dispatch msg)
    (cond ((eq? msg 'translate) translate)
          ((eq? msg 'translate<-) translate2)
          ((eq? msg 'learn) learn)
          (else (error "wrong message - dispatch"))))
  (define (translate word)
    (careful-cdr (assoc-car word dictionary)))
  (define (translate2 word)
    (careful-car (assoc-cdr word dictionary)))
  (define (learn word1 word2)
    (generate (cons (cons word1 word2) dictionary)))
  dispatch)