Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn mcons [first next]
- {:first (ref first)
- :next (ref next)})
- (def L1 (mcons 1 (mcons 2 (mcons 3 nil))))
- (def L2 (mcons 4 nil))
- (defn mlast-cell [mcol]
- (cond (empty? mcol) nil
- (empty? (deref (:next mcol))) mcol
- :else (mlast-cell (deref (:next mcol)))))
- (defn append! [l1 & lists]
- (if (empty? lists)
- l1
- (let [head (first lists)
- r (rest lists)
- l (mlast-cell l1)]
- (if (nil? l1)
- (apply append! lists)
- (do
- (dosync
- (ref-set (:next l) head))
- (apply append! lists))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement