No matching definitions.

tur/zipper

stdlib/zipper.tur

typed Zipper[A]: 1D list zipper with typed focus and neighbors.

Runtime layout: left array, left_len, focus, right array, right_len.

Moves are O(n): each one copies both neighbour arrays. For a persistent zipper with O(1) moves and no zipper-free -- over a list (a ZipCursor over zip/cons-traversal) or over any tree (ZipLoc) -- see stdlib/zip.tur.

Since: Phase TC2-B

defopaque

Zipper

(defopaque Zipper [A] :int)

parameterized 1D list zipper with element type A.

Runtime representation is an opaque heap handle (a pointer to a malloc'd { int64_t *left; size_t left_len; int64_t focus; int64_t *right; size_t right_len; }, built and walked by the -raw inline-C helpers below). It is therefore a carrier-compatible :int newtype, NOT a by-value multi-field struct -- modeling it as defstruct would force a 5-field by-value layout that does not match the pointer the helpers return, and would make (Option (Zipper A)) impossible to thread.

Since: Phase TC2

defn

zipper-new-raw

(zipper-new-raw [left :ptr<void> left-len :int focus :int right :ptr<void> right-len :int])

create a Zipper[A] from left array, focus, and right array.

Ownership: zipper-new does NOT take ownership of left / right. It memcpys them into freshly allocated buffers that the Zipper owns. The caller retains responsibility for freeing the original left / right pointers it passed in. zipper-free later frees the copies.

leftpointer to left neighbor array (int64_t*); leftmost = furthest from focus
left-lennumber of elements in left
focusfocused element of type A
rightpointer to right neighbor array (int64_t*); rightmost = furthest from focus
right-lennumber of elements in right

A new Zipper[A].

(let [l (make-left-arr)
      r (make-right-arr)
      z (zipper-new l 2 5 r 2)]
  (free l) (free r)             ; caller retains l / r ownership
  ... use z ...
  (zipper-free z))             ; frees the copies inside z

Since: Phase TC2

defn

zipper-new

(zipper-new [A])

by-value: recover A from the typed focus element.

defn

zipper-focus-raw

(zipper-focus-raw [z :int])

return the focused element of a Zipper[A].

zZipper[A]

The focused element of type A.

(zipper-focus z)  ; => focused element

Since: Phase TC2

defn

zipper-focus

(zipper-focus [A])

by-value: return the focused element typed as A.

defn

zipper-move-left-raw

(zipper-move-left-raw [z :int])

move the focus one step to the left; returns Option[Zipper[A]].

zZipper[A]

some(new-zipper) if left neighbor exists, none otherwise.

(zipper-move-left z)  ; => some(z') or none

Since: Phase TC2

defn

zipper-move-left

(zipper-move-left [A])

by-value: some(z') if a left neighbor exists, else none.

defn

zipper-move-right-raw

(zipper-move-right-raw [z :int])

move the focus one step to the right; returns Option[Zipper[A]].

zZipper[A]

some(new-zipper) if right neighbor exists, none otherwise.

(zipper-move-right z)  ; => some(z') or none

Since: Phase TC2

defn

zipper-move-right

(zipper-move-right [A])

by-value: some(z') if a right neighbor exists, else none.

defn

zipper-free-raw

(zipper-free-raw [z :int])

free a Zipper[A] and its neighbor arrays.

zZipper[A] to free
(zipper-free z)

Since: Phase TC2

defn

zipper-free

(zipper-free [A])

by-value: free a Zipper[A] and its neighbor arrays.