Skip to content

Consider allowing find-last-by-pos on non-position tracking zipper #285

Open
@lread

Description

Problem/Opportunity

Currently rewrite-clj.zip/find-last-by-pos requires a position tracking zipper.
The position tracking zipper tracks and updates positions as the zipper is changed.

A use case came on Slack today where someone wanted to use find-last-by-pos but with a list of locations found by an external tool. The flow is:

  • let ex-poses = list of row/cols found by an external tool
  • open a zipper in rewrite-clj
  • for each pos in ex-poses
    • find node by pos in zipper
    • make a change to zipper

This won't work on a position-tracking zipper. When the zipper is changed, it will update the row/col positions, and therefore, only the first ex-poses will be found.

And it won't work on a non-position because rewrite-clj throws if you attempt to use a find-last-by-pos on a non-position tracking zipper.

Proposed Solution

Allow find-last-by-pos to work on a non-position tracking zipper to support the use above use case.

Alternative Solutions

  1. A position tracking zipper could also save original loaded row/rols and we could allow searching by either real row/col or original row/col. But that would be a bigger change API-wise, I think. And also doesn't seem like a better alternative.

Additional context

  1. Other zipper functions currently require a position-tracking zipper. They'll need to be reviewed in the same context as find-last-by-pos and updated accordingly.
  2. These other functions might be used internally by the paredit API. The paredit API still needs a position-tracking zipper, but its enforcement was likely incidental. We might need to make it explicit.
  3. We'll need to make it clear to users what they are getting into if they use pos fns on a non-position-tracking zipper vs a position-tracking zipper. Docstrings will need to be updated. Explicit examples in the user guide will also be helpful.

Action

I can follow up by looking into this and, eventually, write up a PR.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status

      Medium Priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions