April 2012
Intermediate to advanced
296 pages
7h 3m
English
In Clojure, a function call is simply a list whose first element resolves to a function. For example, this call to str concatenates its arguments to create a string:
(str "hello" " " "world") | |
-> "hello world" |
Function names are typically hyphenated, as in clear-agent-errors. If a function is a predicate, then by convention its name should end with a question mark. As an example, the following predicates test the type of their argument, and all end with a question mark:
(string? "hello") | |
-> true | |
| |
(keyword? :hello) | |
-> true | |
| |
(symbol? 'hello) | |
-> true |
To define your own functions, use defn:
(defn name doc-string? attr-map? [params*] body) |
The attr-map associates metadata with the function’s var. It’s ...
Read now
Unlock full access