In the Wild

The best way to get a feeling for records and protocols is to see them in action in real code.

For that let’s return to the Clostache templating library, which you will recall takes most of the pain out of the substitute this value in the HTML task that virtually all web applications need to perform. To make Clostache work you need a template string and a map of values:

 (require ​'clostache.parser​)
 
 (​def​ template ​"The book {{title}} is by {{author}}"​)
 
 (​def​ values {:title ​"War and Peace"​ :author ​"Tolstoy"​})

And you can use the Clostache render function to populate the template with your values:

 ;; Gives you "The book War and Peace is by Tolstoy"
 
 (clostache.parser/render template values)

One of the more powerful ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.