Java Magazine, Sept/Oct 2017
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 71 jvm languages Notice the expressiveness of the function name Allowing special characters such as the hyphen or greater than symbol in function names enables you to write concise yet expressive function names especially for transforming data from one structure to another My function takes in a single parameter my list and calls the name function which converts its argument to a string In this case the argument is the first item from my list I could rewrite this code using destructuring as well ns demo hello transform defn first keyword string head tail name head This code is quite a bit more expressive wouldnt you agree In Clojure you can destructure lists maps vectors and much more Destructuring quickly becomes a standard part of Clojure development especially considering how often large data structures such as lists and maps are passed around The Macro System A trait heavily inherited from other Lisp languages is Clojures support for macros which I referred to previously If youve been working with Java for most of your career you might not be familiar with the concept of macros A macro is evaluated at compile time and expands into code in a way similar to that of a compiler extension similar to the preprocessor in C Macros are extremely powerful and very commonly used in Clojure In fact many of the core constructs in Clojure are actually merely macros For example a very common library for web development named Compojure uses macros to allow you to define URL routes and dispatch incoming requests that match those routes to functions After pulling the Compojure dependency into your codebase you can simply define your routes using the following syntax
You must have JavaScript enabled to view digital editions.