Though stacker was simple, we covered many of the foundational ideas of implementing languages in Racket. Our next tutorials will build on these:
The reader must provide a function called read-syntax. Racket passes two arguments to this function: the to the source file, and an input for reading the source code.
After converting the source to S-expressions, the function must return Racket code describing a module (packaged as a syntax object).
Back at the source file, Racket replaces the source code with this module code.
The expander must provide a called #%module-begin. Racket takes the code from inside the module expression generated by the reader and passes it to this macro.
This macro must return new Racket code, again packaged as a syntax object. Racket replaces the module expression generated by the reader with this new code.
Once the expander finishes its work, the new language has been translated into ordinary Racket code. It’s evaluated as a Racket program to produce a result.
A syntax object can also hold a reference to the at a certain point in the program, so that code inside the syntax object can see all the variables defined at that point. We can use the #' prefix to turn any code into a syntax object, by converting it to a datum and capturing its lexical context.