Notation Conventions

The following notation conventions are used throughout the book.

Literal code examples use the following font:

 (+ 2 2)

The result of executing a code example is preceded by ->.

 (+ 2 2)
 -> 4

Where console output cannot easily be distinguished from code and results, it’s preceded by a pipe character (|).

 (println ​"hello"​)
 | hello
 -> nil

When introducing a Clojure form for the first time, we’ll show the grammar for the form like this:

 (example-fn required-arg)
 (example-fn optional-arg?)
 (example-fn zero-or-more-arg*)
 (example-fn one-or-more-arg+)
 (example-fn & collection-of-variable-args)

The grammar is informal, using ?, *, +, and & to document different argument-passing styles, as shown previously.

Clojure code is organized into libs (libraries). Where examples in the book depend on a library that’s not part of the Clojure core, we document that dependency with a require form:

 (require '[lib-name :refer [var-names+] :as alias])

The require form has several options. The :refer option can be used to make either specific vars (or all vars with :all) available in the current namespace. The :alias option can be used to create an alias for references to the library. For example, a commonly used function is file, from the clojure.java.io library:

 (require '[clojure.java.io :as io])
 (io/file ​"hello.txt"​)
 -> #<File hello.txt>

Clojure returns nil from a successful call to require. For brevity, this is omitted from the example listings.

While reading the book, you’ll enter code in an interactive environment called the REPL. The REPL prompt looks like this:

 user=>

The user in the prompt indicates the namespace you’re currently working in. For most of the examples, the current namespace is irrelevant. Where the namespace is irrelevant, we use the following syntax for interaction with the REPL:

 (+ 2 2) ​; input line without namespace prompt
 -> 4 ​; return value

In those instances where the current namespace is important, we use this:

 user=>​ (+ 2 2) ​; input line with namespace prompt
 -> 4 ​; return value
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.253