In the Wild
As you might expect, it’s easy to find very familiar-looking examples of if, when, cond, and case. Here, for instance, are a few lines pulled from Leiningen:
| (when (real-directory? f) |
| (doseq [child (.listFiles f)] |
| (delete-file-recursively child silently))) |
We may not follow the details, but the general idea of this code is not hard to work out: when f is a real directory—that is, not a file or a symbolic link—then delete it and all of its contents.
Here’s another snippet, also from Leiningen:
| (if (.isDirectory entry) |
| (.mkdirs f) |
| (do (.mkdirs (.getParentFile f)) |
| (io/copy (.getInputStream jar entry) f))) |
If entry is a directory, then do this; otherwise do something else.
Dot What? | |
---|---|
The reason for the funny un-Clojurelike ... |
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.