Skip to Main Content
Programming Clojure, 3rd Edition
book

Programming Clojure, 3rd Edition

by Alex Miller, Stuart Halloway, Aaron Bedra
February 2018
Intermediate to advanced content levelIntermediate to advanced
304 pages
7h 11m
English
Pragmatic Bookshelf
Content preview from Programming Clojure, 3rd Edition

Functions

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*] prepost-map? body)

The name is a symbol naming the function (implicitly defined ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Kotlin

Programming Kotlin

Venkat Subramaniam
Getting Clojure

Getting Clojure

Russ Olsen

Publisher Resources

ISBN: 9781680505719Errata Page