lspector/taggp — Issue #10: better ways of refactoring
Author: etosch
Created: 2012-02-13 01:22:11+00:00
State: open

I thought I'd use this "issue" more as a discussion.

If you take a look at the newly refactored [tags.clj](https://github.com/lspector/taggp/blob/refactor/src/taggp/tags.clj) and [recursion.clj](https://github.com/lspector/taggp/blob/refactor/src/taggp/exp/recursion.clj), you'll see that recursion.clj redefines all of eval-with-tagging. I had tried to abstract out all of the consequents of the conditional, so that eval-with-tagging for each condition would be calling
```clojure
(cond (pred-fn? expression) (eval-pred-fn expression tag-space steps default-value)
(another-pred-fn? expression) (trampoline eval-another-pred-fn expression tag-space steps default-value)
...
```
where the trampolined expressions replaced the recur call. Unfortunately this lead to stack over flows in the else clause, presumably due to the accumulation of calls on the stack from the un-trampolined call in its loop. I thought this might be a more elegant way to go, so instead of copying and pasting over the entire eval-with-tagging function, we could just modify the constituent eval functions (thereby also limiting the number of newly introduced bugs). However, to make this work, I would need to rethink the recursive calls in eval-with-tagging to handle the evaluation with args (presumably by carrying in it some extra variables to hold the deferred function and a queue of its args).

Anyone have any better thoughts on this matter?