O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deriving a query language using macros

To be sure, we could refactor the preceding lookup function again and shrink it to a manageable size. In fact, implementing solutions using first-class functions is the preferred approach in 9 out of 10 cases. However, it's useful to know other approaches for the proverbial 10th case. With the preceding function-based approach understood, there are other ways of implementing syntaxes, which are otherwise known as Domain-specific Languages (DSLs). The most popular approach in Lisp is using a macro.

Since Clojure syntax is made up of data (homoiconic), we can transform it similar to any other piece of data flowing through our system. Macros are facilities that let us perform this code transformation. In this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required