I tried to design a Scheme interpreter which is non-recursive, using a stack and pointer to walk on the AST and evaluate.
Things are just fine if I only need to tackle with pure procedure calls. However, once macros comes, the irregular syntax makes it hard to write a non-recursive routine. (because of the mixture of different semantics) What's worse, the non-recursive approach seemingly becomes incredibly complex when taking built-in macros (like if, conf let, etc.) into account.
Any good suggestions on implementing a non-recursive interpreter? Or any materials on that? I've googled hard but found nothing.
And, I wonder whether the mainstream Scheme interpreters use this kind of approach. Maybe I can just write in recursion and it won't be blamed.
syntax-rulesthen yes, you can sneak by with simple, dumb, pattern expansion.syntax-casesupports arbitrary scheme so you'd need to run your interpreter in 2 phases - Daniel Gratzerletis a macro too. An expression like(let ((foo 42) (bar 10)) (+ foo bar))expands to((lambda (foo bar) (+ foo bar)) 42 10). - Chris Jester-Young