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

Vars, Bindings, and Namespaces

One of the most important tools in a programming language is the ability to name and remember values or functions for later use. In Clojure, a namespace is a collection of names (symbols) that refer to vars. Each var is bound to a value. Let’s consider vars more closely.

Vars

When you define an object with def or defn, that object is stored in a Clojure var. For example, the following def creates a var named user/foo:

 (​def​ foo 10)
 -> #​'user/foo

The symbol user/foo refers to a var that is bound to the value 10. If you ask Clojure to evaluate the symbol foo, it will return the value of the associated var:

 foo
 -> 10

The initial value of a var is called its root binding. Sometimes it’s useful to have thread-local ...

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