Description
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.