Skip to content

Instantly share code, notes, and snippets.

View cmoore's full-sized avatar
🆑

Clint Moore cmoore

🆑
View GitHub Profile

Reader Macros in Common Lisp

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

Macros and read-macros see your program at different stages. Macros get hold of the program when it has already been parsed into Lisp objects by the reader, and read-macros operate on a program while it is still text. However, by invoking read on this text, a read-macro can, if it chooses, get parsed Lisp objects as well. Thus read-macros are at least as powerful as ordinary macros.

galleryDispatch ai@(\x -> head (pElements x) -> "u") =
case requestMethod (a_env ai) of
POST -> do
dbg "galleryDispatch: POST on /upload."
let env = a_env ai
case ((,) <$> lookup "Content-Type" (http env)
<*> lookup "Content-Length" (http env)) of
Nothing -> do
dbg "Ack!"
redirect' "/profile"