chapter twenty one
The functions and macros in this chapter are predominantly related to Java interoperation, the part of the standard library that sits closer to the Java runtime. Clojure still offers a functional view over Java’s mutable world offering a syntax that is concise and readable. The following is a summary of what is described in the chapter:
- dot "." is a versatile special form to access Java methods and attributes. double-dot ".." is useful to assemble chained calls while "doto" concatenates side-effecting calls instead.
- new creates a new instance of an object.
- try and catch (and related special forms finally and throw) are the fundamental mechanism for exception handling in Clojure.
- ex-info and ex-data builds on top of Java exception mechanism by hiding some of the low level syntax and offering a mechanism to transport data with exceptions.
- bean is a macro that wraps Java objects in map-like interfaces.
- The functions in the clojure.reflect namespace perform introspection on the structure and content of Java classes.
- Clojure also has a rich set of functions to deal with Java arrays. make-array is just one of the many ways to create an array from Clojure. Macros like aset, amap or areduce are useful to transform the content of the array. The section also contains a brief explanation of array macro variants to leverage primitive types (
int,boolean,byteand so on).