clojure.zip - insert after replace at top is ignored instead of throwing

Description

Per https://ask.clojure.org/index.php/12840/inserting-at-top-of-zipper-doesnt-throw-after-change

Inserting at the top throws:

(require '[clojure.zip :as z]) (-> (z/vector-zip []) (z/insert-right :foo) z/root) ;; Execution error: Insert at top

However, making any edit first will cause the insert to instead be silently ignored rather than throw:

(-> (z/vector-zip []) (z/replace []) (z/insert-right :foo) z/root) ;; []

Cause: z/replace sets :changed? true in the path slot of the loc and z/insert-left and z/insert-right (and z/remove) check whether the path is nil (which it now isn't).

Approach: Probably the simplest approach would be to have a more refined check in insert-left and insert-right. Another option might be to change replace somehow.

Environment

None

Activity

Show:

Details

Assignee

Reporter

Labels

Approval

Triaged

Priority

Affects versions

Created April 10, 2023 at 3:44 PM
Updated April 10, 2023 at 3:44 PM