Skip to content

Commit 7aed72e

Browse files
committed
add :default and no matching tag info to reader conditional guide
1 parent 4df9e32 commit 7aed72e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

content/guides/reader_conditionals.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ toc::[]
1212

1313
Reader conditionals are a feature added in Clojure 1.7. They are designed to allow different dialects of Clojure to share common code that is mostly platform independent, but contains some platform dependent code. If you are writing code across multiple platforms that is mostly independent you should separate `.clj` and `.cljs` files instead.
1414

15-
Reader conditionals are integrated into the Clojure compiler, and don't require any extra tooling beyond Clojure 1.7 or greater. To use reader conditionals, all you need is for your file to have a `.cljc` extension and to use Clojure 1.7 or ClojureScript 0.0-3196 or higher. Reader conditionals are expressions, and can be manipulated like ordinary Clojure expressions. For more technical details, see the reference page on <<xref/../../reference/reader#,the reader>>.
15+
Reader conditionals are integrated into the Clojure reader, and don't require any extra tooling beyond Clojure 1.7 or greater. To use reader conditionals, all you need is for your file to have a `.cljc` extension and to use Clojure 1.7 or ClojureScript 0.0-3196 or higher. Reader conditionals are expressions, and can be manipulated like ordinary Clojure expressions. For more technical details, see the reference page on <<xref/../../reference/reader#,the reader>>.
1616

1717
There are two types of reader conditionals, standard and splicing. The standard reader conditional behaves similarly to a traditional `cond`. The syntax for usage is `#?` and looks like:
1818

1919
[source,clojure]
2020
----
2121
#?(:clj (Clojure expression)
2222
:cljs (ClojureScript expression)
23-
:cljr (Clojure CLR expression))
23+
:cljr (Clojure CLR expression)
24+
:default (fallthrough expression))
2425
----
2526

27+
The platform tags `:clj`, etc are a fixed set of tags hard-coded into each platform. The `:default` tag is a well-known tag to catch and provide an expression if no platform tag matches. If no tags match and `:default` is not provided, the reader conditional will read nothing (not nil, but as if nothing was read from the stream at all).
28+
2629
The syntax for a splicing reader conditional is `#?@`. It is used to splice lists into the containing form. So the Clojure reader would read this:
2730

2831
[source,clojure]

0 commit comments

Comments
 (0)