In the Wild

Real-life Clojure functions are full of let expressions. In fact, let is one of the most commonly used Clojure features, up there with defn and def. If, for example, you look at the Ring source code you will find the parse-params function. Here’s a slightly simplified version of it:

 (​defn​ parse-params [params encoding]
  (​let​ [params (codec/form-decode params encoding)]
  (​if​ (map? params) params {})))

Without diving into the belts and pulleys of Ring, we can deduce that parse-params decodes some raw parameter data into a value that is either a map or something else, presumably nil. Once it has the result of that decoding bound to params—courtesy of let—it proceeds to return the decoded value if it is indeed a map, or an empty ...

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.