You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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.
The text was updated successfully, but these errors were encountered:
KingMob
changed the title
Short circuit prewalk
Feature request: Short circuit prewalk
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.
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?
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 acomment
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
reduced
fits existing short-circuiting methods better, and allows you still submit a changed subtree after you've decided you're done with it.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.
The text was updated successfully, but these errors were encountered: