Hi @samdphillips, big apology if I’m just being a dummy here, but it doesn’t seem to work for (forthify ’(– 1)). Did you mean something else? I’m looking over the code to try and understand it. The addition of the extra combine function really threw me, haha. Cheers.
I made it work more correctly with 2+ argument case and took out the single argument case.
Aaah, sorry for my confusion. Just wanted to clarify before I start trying to figure out how it works. Cheers :)
Adding two match clauses at the top would catch those cases: [(list '+ x) (forthify x)]
[(list '- x) (forthify `(- 0 ,x))]
No problem
Just to see if I’m understanding it right: a) If you have a two-argument form, like (+ 3 4), that is just transformed to (3 4 +).
b) If there is an extra tail following the above case (+ 3 4 ,rest), we:
1. forthify the initial two-argument form to (3 4 +), and then iterate over each element in the tail.
2. IF that element is an atom, forthify turns it into a list, allowing us to append indiscriminately.
ELSE If it's a list (op a b). we forthify it as we did the initial expression and append that.
Basically, folding over a list using append, re-ordering elements in the event that they are themselves list, and otherwise just appending them to the end of the list. The only “special” thing, is that the first list of (op a b) is not nested despite itself being an op+rand combination.
I’m sure you have a million more important things to do than read over that, but whenever you get the time if you could just let me know if it sounds about right, that would be greatly appreciated. Thanks again for coming up with the solution and allowing me to learn from it :)