Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn mcons [first next]
  2.   {:first (ref first)
  3.    :next (ref next)})
  4.  
  5. (def L1 (mcons 1 (mcons 2 (mcons 3 nil))))
  6. (def L2 (mcons 4 nil))
  7.  
  8. (defn mlast-cell [mcol]
  9.   (cond (empty? mcol) nil
  10.         (empty? (deref (:next mcol))) mcol
  11.         :else (mlast-cell (deref (:next mcol)))))
  12.  
  13. (defn append! [l1 & lists]
  14.   (if (empty? lists)
  15.     l1
  16.     (let [head (first lists)
  17.           r (rest lists)
  18.           l (mlast-cell l1)]
  19.       (if (nil? l1)
  20.         (apply append! lists)
  21.         (do
  22.           (dosync
  23.            (ref-set (:next l) head))
  24.           (apply append! lists))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement