Back
next (clj)
(source)function
(next loc)
Moves to the next loc in the hierarchy, depth-first. When reaching
the end, returns a distinguished loc detectable via end?. If already
at the end, stays there.
Examples
clojure
"(ns autodoc.build-html
\"This is the namespace that builds the HTML pages themselves.
It is implemented with a number of custom enlive templates.\"
{:skip-wiki true, :author \"Tom Faulhaber\"}
(:refer-clojure :exclude [empty complement])
(:import [java.util.jar JarFile]
[java.io File FileWriter BufferedWriter StringReader
BufferedInputStream BufferedOutputStream
ByteArrayOutputStream FileReader FileInputStream]
[java.util.regex Pattern])
(:require [clojure.string :as str])
(:use [net.cgrand.enlive-html :exclude (deftemplate)]
[clojure.java.io :only (as-file file writer)]
[clojure.java.shell :only (sh)]
[clojure.pprint :only (pprint cl-format pprint-ident
pprint-logical-block set-pprint-dispatch
get-pretty-writer fresh-line)]
[clojure.data.json :only (pprint-json)]
[autodoc.collect-info :only (contrib-info)]
[autodoc.params :only (params expand-classpath)])
(:use clojure.set clojure.java.io clojure.data clojure.java.browse
clojure.inspector clojure.zip clojure.stacktrace))")
(defmethod test-dispatch true [avec]
(pprint-logical-block :prefix "[" :suffix "]"
(loop [aseq (seq avec)]
(when aseq
(write-out (first aseq))
(when (next aseq)
(.write ^java.io.Writer *out* " ")
(pprint-newline :linear)
(recur (next aseq)))))))
clojure
(ns clojure.test-clojure.clojure-zip
(:use clojure.test)
(:require [clojure.zip :as zip]))
; zipper
;
; seq-zip
; vector-zip
; xml-zip
;
; node
; branch?
; children
; make-node
; path
; lefts
; rights
; down
; up
; root
; right
; rightmost
; left
; leftmost
;
; insert-left
; insert-right
; replace
; edit
; insert-child
; append-child
; next
; prev
; end?
; remove
marick/Midje
(ns midje.parsing.1-to-explicit-form.t-facts
(:require [midje.parsing.1-to-explicit-form.facts :as facts :refer :all]
[midje.sweet :refer :all]
[midje.test-util :refer :all]
[midje.parsing.2-to-lexical-maps.expects :refer [expect]]
[midje.parsing.2-to-lexical-maps.fakes :refer [fake]]
[midje.parsing.2-to-lexical-maps.data-fakes :refer [data-fake]]
[pointer.core :refer [line-number-known]]
[clojure.zip :as zip]
[midje.config :as config]))
(fact "can identify the head of a form that's already been expanded"
(doseq [head `(expect fake data-fake)]
(let [z (zip/seq-zip `(111 (~head 1 2 '(3)) "next"))
skippable (-> z zip/down zip/next zip/down)]
skippable => already-expanded?)))
BetterThanTomorrow/calva
(ns pez-rewrite-clj.zip
"Client facing facade for zipper functions"
(:refer-clojure :exclude [next find replace remove
seq? map? vector? list? set?
print map get assoc])
(:require [pez-rewrite-clj.zip.base :as base]
[pez-rewrite-clj.parser :as p]
[pez-rewrite-clj.zip.move :as m]
[pez-rewrite-clj.zip.findz :as f]
[pez-rewrite-clj.zip.editz :as ed]
[pez-rewrite-clj.zip.insert :as ins]
[pez-rewrite-clj.zip.removez :as rm]
[pez-rewrite-clj.zip.seqz :as sz]
[clojure.zip :as z]))
;; **********************************
;; Originally in pez-rewrite-clj.zip.move
;; **********************************
(def right
"See [[move/right]]"
m/right)
(def left
"See [[move/left]]"
m/left)
(def down
"See [[move/down]]"
m/down)
(def up
"See [[move/up]]"
m/up)
(def next
"See [[move/next]]"
m/next)
(def end?
"See [[move/end?]]"
m/end?)
(def rightmost?
"See [[move/rightmost?]]"
m/rightmost?)
(def leftmost?
"See [[move/leftmost?]]"
m/leftmost?)
(def prev
"See [[move/prev]]"
m/prev)
(def leftmost
"See [[move/leftmost]]"
m/leftmost)
(def rightmost
"See [[move/rightmost]]"
m/rightmost)
;; **********************************
;; Originally in pez-rewrite-clj.zip.findz
;; **********************************
(def find
"See [[findz/find]]"
f/find)
(def find-last-by-pos
"See [[findz/find-last-by-pos]]"
f/find-last-by-pos)
(def find-depth-first
"See [[findz/find-depth-first]]"
f/find-depth-first)
(def find-next
"See [[findz/find-next]]"
f/find-next)
(def find-next-depth-first
"See [[findz/find-next-depth-first]]"
f/find-next-depth-first)
(def find-tag
"See [[findz/find-tag]]"
f/find-tag)
(def find-next-tag
"See [[findz/find-next-tag]]"
f/find-next-tag)
(def find-tag-by-pos
"See [[findz/tag-by-pos]]"
f/find-tag-by-pos)
(def find-token
"See [[findz/find-token]]"
f/find-token)
(def find-next-token
"See [[findz/find-next-token]]"
f/find-next-token)
(def find-value
"See [[findz/find-value]]"
f/find-value)
(def find-next-value
"See [[findz/find-next-value]]"
f/find-next-value)
marick/fp-oo
(require '[clojure.zip :as zip])
(def all-vectors
(fn [tree]
(letfn [(all-from-zipper [so-far zipper]
(cond (zip/end? zipper)
so-far
(zip/branch? zipper)
(all-from-zipper so-far (zip/next zipper))
(vector? (zip/node zipper))
(all-from-zipper (cons (zip/node zipper) so-far)
(zip/next zipper))
:else
(all-from-zipper so-far (zip/next zipper))))]
(reverse (all-from-zipper '() (zip/seq-zip tree))))))
(def all-vectors-2
(fn [tree]
(letfn [(all-from-zipper [so-far zipper]
(cond (zip/end? zipper)
so-far
(vector? (zip/node zipper))
(all-from-zipper (cons (zip/node zipper) so-far)
(zip/next zipper))
:else
(all-from-zipper so-far (zip/next zipper))))]
(reverse (all-from-zipper '() (zip/seq-zip tree))))))
(def first-vector
(fn [tree]
(letfn [(all-from-zipper [zipper]
(cond (zip/end? zipper)
nil
(vector? (zip/node zipper))
(zip/node zipper)
:else
(all-from-zipper (zip/next zipper))))]
(all-from-zipper (zip/seq-zip tree)))))
;;; The clever thing I'm doing is to want to extract out the part that
;;; happens in every case: using `zip/next` and making the recursive
;;; call. That is done by creating a function `advancing`. The
;;; interesting thing is that `advancing` doesn't need to be given the
;;; zipper. It can instead be given a function (`flow`) that does
;;; whatever work is required before `zip/next` is called.
;;;
;;; Why doesn't `advancing` need to be given a zipper? Because *each*
;;; call to `do-node` provides a new zipper, and any of the functions
;;; given to `advancing` can close over it. Therfore, they can
;;; present to `advancing` an argument-free function that it should call,
;;; knowing that function encapsulates the current value of the
;;; zipper.
(def tumult
(fn [form]
(letfn [(advancing [flow]
(-> (flow) zip/next do-node))
(do-node [zipper]
(cond (zip/end? zipper)
zipper
(at? zipper '+)
(advancing (fn [] (zip/replace zipper 'PLUS)))
(above? zipper '-)
(advancing (fn [] (zip/append-child zipper 55555)))
(above? zipper '*)
(advancing (fn [] (zip/replace zipper
'(/ 1 (+ 3 (- 0 9999))))))
(at? zipper '/)
(advancing (fn []
(-> zipper
zip/right
zip/remove
zip/right
zip/remove
(zip/insert-right (-> zipper zip/right zip/node))
(zip/insert-right (-> zipper zip/right zip/right zip/node))
zip/next
do-node)))
:else
(advancing (constantly zipper))))]
(-> form zip/seq-zip do-node zip/root))))