Error formatting macro: pagetree: java.lang.NullPointerException
Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History


Now we have a Compiler written in Clojure (ClojureScript) we should explore making compilation phases pluggable. This will allow the development of more powerful tools like source analyzers and type checkers.

Analysis phase seems the most useful phase to expose.


Racket's Approach

Racket achieves this via macros.

For example, #%module-begin (a macro) can be overridden to perform some custom analysis. 


Here is how #%module-begin is used by the compiler.


macroexpands to ...


We can see that module-begin wraps every form in the body of a module.

We can override #%module-begin to perform custom analysis.

This example first expands each form after passing them to #%plain-module-begin, then performs some type checking at compile time with type-check-module-body.

(This example is from Typed Racket, see: Advanced Macrology and the Implementation of Typed Scheme)


  • hiredman (paraphrased from #clojure): Shouldn't use "binding" form to effect compilation of forms, because it depends on how the "binding" macro expands. Bindings might stop working if the form is wrapped in a "try"



  • hiredman: Perhaps extend the "ns" declaration to allow compiler extensions


  1. Provide a map of hooks to the compiler via a :compiler-hooks option for the "ns" macro
  2. Annotate forms with reader metadata for the Compiler to dispatch on

Example - Type Checking

Library Code

User Code


  • How should the :compiler-hooks form work?