sydney.lambda
2019-8-25 16:29:22

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.


samdphillips
2019-8-25 16:35:31

I made it work more correctly with 2+ argument case and took out the single argument case.


sydney.lambda
2019-8-25 16:38:33

Aaah, sorry for my confusion. Just wanted to clarify before I start trying to figure out how it works. Cheers :)


samdphillips
2019-8-25 16:39:10

Adding two match clauses at the top would catch those cases: [(list '+ x) (forthify x)] [(list '- x) (forthify `(- 0 ,x))]


samdphillips
2019-8-25 16:39:34

No problem


sydney.lambda
2019-8-25 16:52:06

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.


sydney.lambda
2019-8-25 16:53:08

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 :)