liveBook · Manning

Zipper node

As explained in Clojure: The Essential Reference

node is a Clojure zipper API function that retrieves the data at the current zipper location.

`clojure.zip/node` returns the data at a zipper’s current location. It does not move the location. A node is ordinary Clojure data; a location also carries the position needed to navigate or edit the tree. section 8.4.4

Read the current node

(require '[clojure.zip :as zip]) (def loc (zip/vector-zip [1 2 [3 4]])) (zip/node loc) ;; [1 2 [3 4]] (-> loc zip/down zip/node) ;; 1 (-> loc zip/down zip/right zip/right zip/node) ;; [3 4] section 8.4.4

Use navigation functions such as `down` or `right` to select a location before calling `node`. For neighboring data without moving focus, `children`, `lefts`, and `rights` are alternatives. After edits, use `root` to retrieve the resulting tree. section 8.4.4

How Clojure: The Essential Reference covers it

How deep it goes
Defines the return value and demonstrates retrieval after navigation and edits, without detailing node implementation.
Examples
Shows node retrieval from vector, sequence, XML, and custom zippers.
What it assumes
Introduces the distinction between zipper locations and node data while using familiar Clojure collections.
What you can do after
Apply it via clojure.zip to inspect data at a selected tree location.
How it connects
Connects zipper locations and navigation with children, lefts, rights, and root.

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.