concept clojure in category dsl

appears as: Clojure
DSLs in Action

This is an excerpt from Manning's book DSLs in Action.

That was the last of the internal DSL implementation patterns that we’ll discuss in this chapter. We’ve discussed various flavors of metaprogramming that you’ll find mostly in dynamic languages like Ruby, Groovy, and Clojure. We also talked about static typing and the benefits that it brings when you’re designing type-safe DSL scripts. In chapters 4, 5, and 6, we’ll get back to all these patterns and discuss each of them, with specific examples in each of the languages.

The languages I’ve selected for this chapter are dynamically typed. I start the chapter by discussing some of the attributes of dynamically typed languages that make good DSLs and why I selected Ruby, Groovy, and Clojure for our discussion. Then we’ll jump right into the implementation part and take you successively through the process of implementing complete DSLs using each of the three languages. We discuss the main features that these languages offer that you’ll frequently use in designing DSLs and some of the rationale for when to select which pattern for your implementation.

Table 5.1. Ruby, Groovy, and Clojure features that make them great choices for your internal DSLs
 

Readability

Duck typing

Metaprogramming

Ruby Flexible syntax, no type annotations, and strong literal support. Supports duck typing and you can use responds_to? to check whether a class responds to a specific message. Has strong support of reflective and generative metaprogramming.
Groovy Flexible syntax, optional type annotations, and strong literal support. Supports duck typing; you have some polymorphism without a common base class. Has strong support for runtime metaprogramming through Groovy metaobject protocol (MOP).
Clojure Syntax is flexible but bound by the prefix form of expressions as in other Lisp variants. You can provide optional type hints to speed up method dispatch, which avoids reflection in Java calls. Supports duck typing as in Ruby or Groovy. Implements compile-time metaprogramming through macros. Clojure is malleable enough to be extended as per the requirements of your DSL.
Listing 5.13. Trade generation in Clojure