Back

end? (clj)

(source)

function

(end? loc)
Returns true if loc represents the end of a depth-first walk

Examples

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
babashka/babashka
(ns babashka.impl.clojure.zip
  {:no-doc true}
  (:require [clojure.zip :as zip]
            [sci.core :as sci :refer [copy-var]]))

(def zip-namespace
  {'zipper       (copy-var zip/zipper zip-ns)
   'seq-zip      (copy-var zip/seq-zip zip-ns)
   'vector-zip   (copy-var zip/vector-zip zip-ns)
   'xml-zip      (copy-var zip/xml-zip zip-ns)
   'node         (copy-var zip/node zip-ns)
   'branch?      (copy-var zip/branch? zip-ns)
   'children     (copy-var zip/children zip-ns)
   'make-node    (copy-var zip/make-node zip-ns)
   'path         (copy-var zip/path zip-ns)
   'lefts        (copy-var zip/lefts zip-ns)
   'rights       (copy-var zip/rights zip-ns)
   'down         (copy-var zip/down zip-ns)
   'up           (copy-var zip/up zip-ns)
   'root         (copy-var zip/root zip-ns)
   'right        (copy-var zip/right zip-ns)
   'rightmost    (copy-var zip/rightmost zip-ns)
   'left         (copy-var zip/left zip-ns)
   'leftmost     (copy-var zip/leftmost zip-ns)
   'insert-left  (copy-var zip/insert-left zip-ns)
   'insert-right (copy-var zip/insert-right zip-ns)
   'replace      (copy-var zip/replace zip-ns)
   'edit         (copy-var zip/edit zip-ns)
   'insert-child (copy-var zip/insert-child zip-ns)
   'append-child (copy-var zip/append-child zip-ns)
   'next         (copy-var zip/next zip-ns)
   'prev         (copy-var zip/prev zip-ns)
   'end?         (copy-var zip/end? zip-ns)
   'remove       (copy-var zip/remove zip-ns)})
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)
marick/fp-oo
(require '[clojure.zip :as zip])


;; For the first set of exercises
(def flattenize
     (fn [tree]
       (letfn [(flatten-zipper [so-far zipper]
                 (cond (zip/end? zipper)
                       so-far
                       
                       (zip/branch? zipper)
                       (flatten-zipper so-far (zip/next zipper))
                       
                       :else
                       (flatten-zipper (cons (zip/node zipper) so-far)
                                       (zip/next zipper))))]
         (reverse (flatten-zipper '() (zip/seq-zip tree))))))


(def tumult
     (fn [form]
       (letfn [(helper [zipper]
                       (cond (zip/end? zipper)
                             zipper
                             
                             (= (zip/node zipper) '+)
                             (-> zipper
                                 (zip/replace 'PLUS)
                                 zip/next
                                 helper)
marick/fp-oo
(require '[clojure.zip :as zip])


(def flatten-zipper
     (fn [so-far zipper]
       (cond (zip/end? zipper)
             so-far

             :else
             (flatten-zipper (cons (zip/node zipper) so-far)
                             (zip/next zipper)))))
     
(def flattenize
     (fn [tree]
       (reverse (flatten-zipper '() (zip/seq-zip tree)))))
     
(def tumult-just-plus
     (fn [form]
       (letfn [(helper [zipper]
                       (cond (zip/end? zipper)
                             zipper
                             
                             (= (zip/node zipper) '+)
                             (-> zipper
                                 (zip/replace 'PLUS)
                                 zip/next
                                 helper)
                             
                             :else
                             (-> zipper zip/next helper)))]
       (-> form zip/seq-zip helper zip/root))))


(def tumult-append-node
     (fn [form]
       (letfn [(helper [zipper]
                       (cond (zip/end? zipper)
                             zipper
                             
                             (= (zip/node zipper) '+)
                             (-> zipper
                                 (zip/replace 'PLUS)
                                 zip/next
                                 helper)

                             (and (zip/branch? zipper)
                                  (= (-> zipper zip/down zip/node) '-))
                             (-> zipper
                                 (zip/append-child 55555)
                                 zip/next
                                 helper)
                             
                             :else
                             (-> zipper zip/next helper)))]
       (-> form zip/seq-zip helper zip/root))))
                       
(def tumult-flip-args
     (fn [form]
       (letfn [(helper [zipper]
                       (cond (zip/end? zipper)
                             zipper
                             
                             (= (zip/node zipper) '+)
                             (-> zipper
                                 (zip/replace 'PLUS)
                                 zip/next
                                 helper)
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))

(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))

(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)))))

(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)))