Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

WhereItemDescriptionExample
allWell-known platform feature namesEach platform has a well-known platform feature when loading or compiling source files.clj, cljs, clr cljr
allReader syntax for conditional expressions

read-cond or #?(feature expr ...) - alternating feature and expression (similar to cond). First feature that is included in the current feature set will result in the expr being read.

(defn my-trim [s]
#?(:clj (.. s toString trim)
:cljs (gstring/trim s)))
allReader syntax for conditional spliced expressionsread-cond-splicing or #?@(feature expr ...) - same as read-cond, but expression must be a java.util.List and will be spliced into the resulting read.
(ns a.b
#?@(:clj [(:require clojure.string)
(:import java.util.Date)]))
allReader syntax for conditional read :default

If no feature is matched in #? or #?@, :default is a well-known keyword indicating a default expression to use instead. If no expression is chosen, nothing (not nil, but literally nothing) is read.

#?(:clj (Foo.) :default [])
all

Allow reader conditional read mode with reader option
{:read-cond :allow}

In allow mode, reader conditional syntax is allowed. Reader conditionals are evaluated and replaced with the result of the appropriate branch.

Reading source files containing reader conditionals without this option results in a runtime exception.

(read-string 
{:read-cond :allow}
"#?(:clj "clj" :default nil)") 
allPreserve reader conditional read mode with reader option
 {:read-cond :preserve}

In preserve mode, the reader-conditional is not replaced by the selected branch but instead returned as a form containing all branches. Tagged literals and nested reader-conditionals in all non-chosen branches will be represented in data form.

(read-string
{:read-cond :preserve}
"#?(:clj foo :cljs bar)")
allRead-conditional data instanceIn preserve mode, this instance may be returned. See below for details on what it supports.
;; Construct like:
(reader-conditional  )
allType-independent tagged literal data instanceIn preserve mode, this instance may be returned. See below for details on what it supports.
;; Construct like:
(tagged-literal "js" {}) 
allNew .cljc extension indicating a portable source file

Clojure, ClojureScript, and ClojureCLR should load both .cljc (which may have reader conditionals) and their own platform-specific files as source files.

For .cljc files: the reader will be invoked with read-cond mode :allow.

For .clj/.cljs files: the reader will be invoked with read-cond disabled. All other read modes (such as the repl) will disable reader conditionals by default. The reader may be invoked with appropriate options to enable this mode.

 

...

The platform feature will be one of: cljcljs, or clrcljr.  The platform feature will always be available when reading. The features default, else, and none are reserved.

...