Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Short circuit prewalk #209

Open
KingMob opened this issue Jan 27, 2023 · 3 comments
Open

Feature request: Short circuit prewalk #209

KingMob opened this issue Jan 27, 2023 · 3 comments

Comments

@KingMob
Copy link

KingMob commented Jan 27, 2023

Problem/Opportunity
It would be handy in some cases to short-circuit a prewalk early. E.g., if there's an :uneval reader literal or a comment block, I'd prefer to stop drilling down in that case.

Proposed Solution
Currently the walk visiting fns should return either a zipper (usually with changes) or nil, to indicate no changes. One way to handle this, then, is to check the returned value with reduced?, and if true, stop processing any further down that subtree.

Alternative Solutions

  1. A sentinel value of some sort could also be returned, but reduced fits existing short-circuiting methods better, and allows you still submit a changed subtree after you've decided you're done with it.
  2. An additional, separate predicate could be used to test for continued subtree processing, and while it would separate the logic between "continue-down-this-subtree" and "this-node-is-interesting", it would require an additional arity, or other changes to the prewalk fn signature.

Additional context
I'm not really coming at this from an editing or linter-fixing angle, I'm more interested in code behavior alteration, and being able to exclude unevaluated subtrees would be handy. In my case, I can't ignore them and rely on the code never being run, because I build lists of fns as I go along, so they still have to be excluded.

Currently, I locate candidate fns, and then search again upwards to see if they're contained in a uneval node or a comment block.

Action
I'm happy to help with any aspect of the solution, though I'm still new to rewrite-clj.

@KingMob KingMob changed the title Short circuit prewalk Feature request: Short circuit prewalk Jan 27, 2023
@lread
Copy link
Collaborator

lread commented Jan 27, 2023

Hi @KingMob! Thanks for raising a feature request.

While I think your idea is interesting, I'm also thinking maybe we could figure out a way to do what you want to do more efficiently without modifying rewrite-clj.

Also when I read:

Currently, I locate candidate fns, and then search again upwards to see if they're contained in a uneval node or a comment block.

I'm not sure, but this feels like the very old #70.
Which I did spend some time thinking about recently-ish.

@KingMob
Copy link
Author

KingMob commented Jan 29, 2023

I must have missed #70 somehow; it seems like it covers my use case, assuming it skips over the whole subtree, and not just that particular node (it's not clear to me that's the case, but I'm still new at rewrite-clj).

I added some comments on your brainstorming doc, but tl;dr: do we need a general skipping ability, or have most people only asked to skip uneval/comment?

@lread
Copy link
Collaborator

lread commented Jan 29, 2023

Cool, thanks @KingMob, I'll follow up in #199.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants