All Versions
69
Latest Version
4.6
Avg Release Cycle
124 days
Latest Release
-

Changelog History
Page 4

  • v2.15 Changes

    :const lets you name primitive values with speedier reference.

    (def constants
     {:pi 3.14
      :e 2.71})
    
    (def ^:const pi (:pi constants))
    (def ^:const e (:e constants))
    

    The overhead of looking up :e and :pi in the map happens at compile time, as (:pi constants) and (:e constants) are evaluated when their parent def forms are evaluated.

  • v2.14 Changes

    The dynamic var *compiler-options* contains a map of options to send to the Clojure compiler.

    ๐Ÿ‘Œ Supported options:

    • ๐Ÿ“‡ :elide-meta: Have certain metadata elided during compilation. This should be set to a collection of keywords.
    • :disable-locals-clearing: Set to true to disable clearing. Useful for using a debugger.

    The main function of the Clojure compiler sets the *compiler-options* from properties prefixed by clojure.compiler, e.g.

    java -Dclojure.compiler.elide-meta='[:doc :file :line]'
    
  • v2.12 Changes

    The new clojure.edn namespace reads edn (http://edn-format.org) data, and should be used for reading data from untrusted sources.

    Clojure's core read* functions can evaluate code, and should not be used to read data from untrusted sources. As of 1.5, *read-eval* ๐Ÿ‘Œ supports a documented set of thread-local bindings, see the doc string for details.

    *read-eval*'s default can be set to false by setting a system property:

    -Dclojure.read.eval=false
    
  • v2.11 Changes

    Most functions that take a collection and return a "modified" version ๐Ÿ“‡ of that collection preserve the metadata that was on the input collection, e.g. conj, assoc, dissoc, etc. One notable ๐Ÿ“‡ exception was into, which would return a collection with metadata nil for several common types of input collections.

    Now the functions into, select-keys, clojure.set/project, and ๐Ÿ“‡ clojure.set/rename return collections with the same metadata as their input collections.

  • v2.10 Changes

    All of the functions that construct sets such as set and sorted-set allow duplicate elements to appear in their arguments, and they are documented to treat this case as if by repeated uses of conj.

    Similarly, all map constructor functions such as hash-map, array-map, and sorted-map allow duplicate keys, and are documented to treat this case as if by repeated uses of assoc.

    As before, literal sets, e.g. #{1 2 3}, do not allow duplicate elements, and while elements can be expressions evaluated at run time such as #{(inc x) (dec y)}, this leads to a check for duplicates at โš™ run time whenever the set needs to be constructed, throwing an ๐Ÿ‘ป exception if any duplicates are found.

    Similarly, literal maps do not allow duplicate keys. New to Clojure ๐ŸŽ 1.5 is a performance optimization: if all keys are compile time constants but one or more values are expressions requiring evaluation at run time, duplicate keys are checked for once at compile time only, not each time a map is constructed at run time.

    • CLJ-1065 Allow duplicate set elements and map keys for all set and map constructors
  • v2.9 Changes

    clojure.string/replace and clojure.string/replace-first are now consistent in the way that they handle the replacement strings: all characters in the replacement strings are treated literally, including backslash and dollar sign characters.

    user=> (require '[clojure.string :as s])
    
    user=> (s/replace-first "munge.this" "." "$")
    ;=> "munge$this"
    
    user=> (s/replace "/my/home/dir" #"/" (fn [s] "\\"))
    ;=> "\\my\\home\\dir"
    

    ๐Ÿ‘ป There is one exception, which is described in the doc strings. If you call these functions with a regex to search for and a string as the replacement, then dollar sign and backslash characters in the replacement string are treated specially. Occurrences of $1 in the replacement string are replaced with the string that matched the first parenthesized subexpression of the regex, occurrences of $2 are replaced with the match of the second parenthesized subexpression, etc.

    user=> (s/replace "x12, b4" #"([a-z]+)([0-9]+)" "$1 <- $2")
    ;=> "x <- 12, b <- 4"
    

    Individual occurrences of $ or \ in the replacement string that you wish to be treated literally can be escaped by prefixing them with a \. If you wish your replacement string to be treated literally and its contents are unknown to you at compile time (or you don't wish to tarnish your constant string with lots of backslashes), you can use the new function clojure.string/re-quote-replacement to do the necessary escaping of special characters for you.

    user=> (s/replace "x12, b4" #"([a-z]+)([0-9]+)"
                         (s/re-quote-replacement "$1 <- $2"))
    ;=> "$1 <- $2, $1 <- $2"
    
  • v2.8 Changes

    For the convenience of those that use Emacs Org mode, ๐Ÿ–จ clojure.pprint/print-table now prints tables in the form used by that mode. Emacs Org mode has features to make it easy to edit such tables, and even to do spreadsheet-like calculations on their ๐Ÿ“š contents. See the Org mode documentation on tables for details.

    user=> (clojure.pprint/print-table [:name :initial-impression]
               [{:name "Rich" :initial-impression "rock star"}
                {:name "Andy" :initial-impression "engineer"}])
    | :name | :initial-impression |
    |-------+---------------------|
    |  Rich |           rock star |
    |  Andy |            engineer |
    
  • v2.7 Changes

    ๐Ÿ–จ There have been enhancements in how the REPL prints values without a ๐Ÿ–จ print-method, specifically Throwable and the fallthrough Object case. ๐Ÿ–จ Both cases now print in a tagged literal data form that can be read by the reader.

    ๐Ÿ–จ Unhandled objects print with the class, hash code, and toString:

    user=> *ns*
    #object[clojure.lang.Namespace 0x55aa628 "user"]
    

    0๏ธโƒฃ Thrown exceptions will still be printed in the normal way by the default ๐Ÿ–จ REPL but printing them to a stream will show a different form:

    user=> (/ 1 0)
    ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:158)
    user=> (println *e)
    #error {
     :cause Divide by zero
     :via
     [{:type java.lang.ArithmeticException
       :message Divide by zero
       :at [clojure.lang.Numbers divide Numbers.java 158]}]
     :trace
     [[clojure.lang.Numbers divide Numbers.java 158]
      [clojure.lang.Numbers divide Numbers.java 3808]
      ;; ... elided frames
      ]}
    

    โž• Additionally, there is a new function available to obtain a Throwable as map data: Throwable->map.

  • v2.6 Changes

    Several important Clojure functions now return sequences that also contain fast reduce() (or in some cases iterator()) paths. In many cases, the new implementations are also faster for lazy sequences

    • repeat - now implements IReduce
    • cycle - implements IReduceInit
    • iterate - implements IReduceInit
    • range - implements IReduce, specialized case handles common case of all longs
    • keys - iterates directly over the keys of a map, without seq or MapEntry allocation
    • vals - iterates directly over the vals of a map, without seq or MapEntry allocation
    • iterator-seq - creates a chunked sequence when previously it was unchunked

    โž• Additionally, hash-maps and hash-sets now provide iterators that walk the data structure directly rather than via a sequence.

    A new interface (IMapIterable) for direct key and val iterators on maps was added. External data structures can use this interface to provide direct key and val iterators via keys and vals.

    These enhancements are particularly effective when used in tandem with transducers via transduce, sequence, into, and eduction.