简体   繁体   中英

How to use clojure.zip in 4clojure

I used followed codes to solve tree re-parenting the question in 4clojure, but the answer is the clojure.zip namespace is not required, under not modified my codes, how can I pass it?

(fn gen-tree
  [nr tree]
  (let [zp (clojure.zip/seq-zip tree)
        pnodes (:pnodes (second
                          (first
                            (filter
                              (fn [[nd :as loc]]
                                (= nr nd))
                              (iterate clojure.zip/next zp)))))]
    (reduce (fn [rs e]
              (concat e (list (remove #(= e %) rs))))
            pnodes)))

You can't. User code on 4clojure is not allowed to load namespaces.

Aside: your code will fail for sufficiently large inputs, because of the reduce/concat problem shown in, for example, Why does reduce give a StackOverflowError in Clojure? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM