2 ms·
The Number Guessing Game Written in YAML as Lisp Interpreted with Python
- PaulHoule 5y agoThis is fun and really easy path to metaprogramming. I did something a lot like this in Java where I could write Java abstract syntax trees in Java for instance write Expression<String> that = add(of("RED"), of("blue")) to represent the expression "RED" + "blue" You could process that Expression in a few different ways, for instance you could evaluate the tree using reflection or you could turn the tree into source code and compile it with javac. Going down that path I found it was more about discovery rather than invention. That is, you will discover the issues that come up around quoting in LISP and develop some answers to them. Also for the exercise to be interesting at you will get into an execution model that is a bit bigger than the original language : for the metaprogramming to be fun at all you want to be able to write Expressions that manipulate Expressions so you end up introducing types that don't really exist in the base language. These are almost trivial to handle using the primitive interpreter style but could be more of a challenge to compile to source code. Some source code is here https://github.com/paulhoule/ferocity https://github.com/paulhoule/ferocity It's been a long time since I worked on it and I need to see if I have more notes explaining the plan behind it, but the idea was to develop "ferocity0" which was a version of the DSL that was good enough to build stubs for some of the language and a large part of the standard library, and then use code generation techniques to create "ferocity1" which would be like "ferocity0" but would cover 100% of the Java language. My current side project is being sidelined by supply chain problems so I might go back into that one.