Home Page Icon
Home Page
Table of Contents for
About the Authors
Close
About the Authors
by Luke VanderHart, Stuart Sierra
Practical Clojure
Copyright
About the Authors
About the Technical Reviewer
Acknowledgments
1. The Clojure Way
1.1. Clojure's Philosophy and Special Features
1.1.1. A Next-Generation Language
1.1.2. Dynamic and Powerful (Yes, It's a Lisp)
1.1.3. The Java Platform
1.2. Functional Programming
1.2.1. Purely Functional Programming
1.2.2. Clojure's Compromise
1.2.3. Immutability
1.2.4. What about Object-Oriented Programming?
1.2.4.1. Structure of a Clojure Program
1.2.5. State Management
1.2.6. State and Identity
1.2.7. Software Transactional Memory
1.3. Summary
2. The Clojure Environment
2.1. "Hello World" in Clojure
2.2. Clojure Forms
2.2.1. Literals
2.2.2. Symbols
2.2.3. Composite Forms
2.2.4. Special Forms
2.3. Writing and Running Source Files
2.4. Vars, Namespaces, and the Environment
2.5. Symbols and Symbol Resolution
2.5.1. Symbol Names
2.5.2. Symbol Resolution and Scope
2.6. Namespaces
2.6.1. Declaring Namespaces
2.6.2. Referencing Namespaces
2.6.3. Structuring Source Files
2.7. Summary
3. Controlling Program Flow
3.1. Functions
3.1.1. First-Class Functions
3.1.2. Defining Functions with fn
3.1.3. Defining Functions with defn
3.1.4. Functions of Multiple Arities
3.1.5. Functions with Variable Arguments
3.1.6. Shorthand Function Declaration
3.2. Conditional Expressions
3.3. Local Bindings
3.4. Looping and Recursion
3.4.1. Tail Recursion
3.4.1.1. Clojure'srecur
3.4.1.2. Using loop
3.5. Deliberate Side Effects
3.5.1.
3.5.1.1. Using do
3.5.1.2. Side Effects in Function Definitions
3.6. Functional Programming Techniques
3.6.1. First-Class Functions
3.6.1.1. Consuming First-Class Functions
3.6.1.2. Producing First-Class Functions
3.6.2. Closures
3.6.3. Currying and Composing Functions
3.6.3.1. Using partial to Curry Functions
3.6.3.2. Using comp to Compose Functions
3.6.4. Putting It All Together
4. Data in Clojure
4.1. How to Represent and Manipulate Data
4.1.1. Nil
4.2. Primitive Types
4.2.1. Numbers
4.2.1.1. Common Numeric Functions
4.2.1.1.1. Addition (+)
4.2.1.1.2. Subtraction (–)
4.2.1.1.3. Multiplication (*)
4.2.1.1.4. Division (/)
4.2.1.1.5. inc
4.2.1.1.6. dec
4.2.1.1.7. quot
4.2.1.1.8. rem
4.2.1.1.9. min
4.2.1.1.10. max
4.2.1.1.11. Equals Function (==)
4.2.1.1.12. Greater-Than Function (<)
4.2.1.1.13. Greater-Than-or-Equals Function (<=)
4.2.1.1.14. Less-Than (>)
4.2.1.1.15. The Less-Than-or-Equals (>=)
4.2.1.1.16. zero?
4.2.1.1.17. pos?
4.2.1.1.18. neg?
4.2.1.1.19. number?
4.2.2. Strings
4.2.2.1. Common String Functions
4.2.2.1.1. str
4.2.2.1.2. subs
4.2.2.1.3. string?
4.2.2.1.4. print & println
4.2.2.2. Regular Expression Functions
4.2.2.2.1. re-pattern
4.2.2.2.2. re-matches
4.2.2.2.3. re-matcher
4.2.2.2.4. re-find
4.2.2.2.5. re-groups
4.2.2.2.6. re-seq
4.2.3. Boolean
4.2.3.1. Common Boolean Functions
4.2.3.1.1. not
4.2.3.1.2. and
4.2.3.1.3. or
4.2.4. Characters
4.2.4.1. char
4.2.5. Keywords
4.2.5.1. keyword
4.2.5.2. keyword?
4.3. Collections
4.3.1. Lists
4.3.1.1. list
4.3.1.2. peek
4.3.1.3. pop
4.3.1.4. list?
4.3.2. Vectors
4.3.2.1. vector
4.3.2.2. vec
4.3.2.3. get
4.3.2.4. peek
4.3.2.5. vector?
4.3.2.6. conj
4.3.2.7. assoc
4.3.2.8. pop
4.3.2.9. subvec
4.3.3. Maps
4.3.3.1. Struct Maps
4.3.3.2. Maps As Objects
4.3.3.2.1. assoc
4.3.3.2.2. dissoc
4.3.3.2.3. conj
4.3.3.2.4. merge
4.3.3.2.5. merge-with
4.3.3.2.6. get
4.3.3.2.7. contains?
4.3.3.2.8. map?
4.3.3.2.9. keys
4.3.3.2.10. vals
4.3.4. Sets
4.3.4.1. Common Set Functions
4.3.4.1.1. clojure.set/union
4.3.4.1.2. clojure.set/intersection
4.3.4.1.3. clojure.set/difference
4.4. Summary
5. Sequences
5.1. What Are Sequences?
5.1.1. Sequenceable Types
5.2. Anatomy of a Sequence
5.3. Constructing Sequences
5.4. Lazy Sequences
5.4.1. An Example of Laziness
5.4.2. Constructing Lazy Sequences
5.4.2.1. Constructing Lazy Sequences Directly
5.4.2.2. Constructing Lazy Sequences Using Sequence Generator Functions
5.4.3. Lazy Sequences and Memory Management
5.5. The Sequence API
5.5.1. Sequence Creation
5.5.1.1. seq
5.5.1.2. vals
5.5.1.3. keys
5.5.1.4. rseq
5.5.1.5. lazy-seq
5.5.1.6. repeatedly
5.5.1.7. iterate
5.5.1.8. repeat
5.5.1.9. range
5.5.1.10. distinct
5.5.1.11. filter
5.5.1.12. remove
5.5.1.13. cons
5.5.1.14. concat
5.5.1.15. lazy-cat
5.5.1.16. mapcat
5.5.1.17. cycle
5.5.1.18. interleave
5.5.1.19. interpose
5.5.1.20. rest
5.5.1.21. next
5.5.1.22. drop
5.5.1.23. drop-while
5.5.1.24. take
5.5.1.25. take-nth
5.5.1.26. take-while
5.5.1.27. drop-last
5.5.1.28. reverse
5.5.1.29. sort
5.5.1.30. sort-by
5.5.1.31. split-at
5.5.1.32. split-with
5.5.1.33. partition
5.5.1.34. map
5.6. Summary
6. State Management
6.1. State in an Immutable World
6.1.1. The Old Way
6.1.2. State and Identity
6.1.3. State and Identity in Clojure
6.1.3.1. Coordinated vs. Independent State
6.1.3.2. Synchronous vs. Asynchronous Updates
6.2. Refs and Transactions
6.2.1. Creating and Accessing refs
6.2.2. Updating refs
6.2.2.1. Transactions
6.2.2.2. Tools for Updating refs
6.2.2.3. Examples
6.3. Atoms
6.3.1. Using Atoms
6.3.2. When to Use Atoms
6.4. Asynchronous Agents
6.4.1. Creating and Updating Agents
6.4.1.1. Update Semantics
6.4.2. Errors and Agents
6.4.2.1. Dealing with Agents in a Failed State
6.4.3. Waiting for Agents
6.4.4. Shutting Down Agents
6.4.5. When to Use Agents
6.5. Vars and Thread-Local State
6.5.1. When to Use Thread-Local Vars
6.6. Keeping Track of Identities
6.6.1. Validators
6.6.2. Watches
6.7. Summary
7. Namespaces and Libraries
7.1. Organizing Clojure Code
7.2. Namespace Basics
7.2.1. Switching Namespaces with in-ns
7.2.2. Referring to Other Namespaces
7.3. Loading Other Namespaces
7.3.1. Loading from a File or Stream
7.3.2. Loading from the Classpath
7.3.2.1. Namespace Names vs. File Names
7.3.2.2. Loading Resources from the Classpath
7.3.2.3. Loading Namespaces from the Classpath
7.3.3. Loading and Referring Namespaces in One Step
7.3.4. Importing Java Classes
7.4. Bringing It All Together: Namespace Declarations
7.5. Symbols and Namespaces
7.5.1. Namespace Metadata
7.5.2. Forward Declarations
7.5.3. Namespace-Qualified Symbols and Keywords
7.5.4. Constructing Symbols and Keywords
7.5.5. Public and Private Vars
7.6. Advanced Namespace Operations
7.6.1. Querying Namespaces
7.6.2. Manipulating Namespaces
7.7. Namespaces As References
7.8. Summary
8. Metadata
8.1. Describing Your Code, in Code
8.2. Reading and Writing Metadata
8.3. Metadata-Preserving Operations
8.4. Read-Time Metadata
8.5. Metadata on Vars
8.5.1. Type Tags
8.5.2. Private Vars
8.6. Metadata on Reference Types
8.7. Summary
9. Multimethods and Hierarchies
9.1. Runtime Polymorphism Without Classes
9.2. Multimethods
9.2.1. Multiple Dispatch
9.2.2. Default Dispatch Values
9.3. Hierarchies
9.3.1. Querying Hierarchies
9.4. Hierarchies with Multimethods
9.4.1. Hierarchies with Java Classes
9.4.2. More Hierarchy Queries
9.4.3. Resolving Conflicts
9.4.4. Type Tags
9.5. User-Defined Hierarchies
9.6. Summary
10. Java Interoperability
10.1. Calling Java from Clojure
10.1.1. Java Interop Special Forms
10.1.2. Java Interop Preferred Forms
10.1.3. Clojure Types and Java Interfaces
10.1.4. Java Arrays
10.1.4.1. Creating Arrays
10.1.4.2. Manipulating Arrays
10.1.4.3. Iterating Over Arrays
10.2. Calling Clojure from Java
10.2.1. Loading and Evaluating Clojure Code
10.2.2. Using Clojure Functions and Vars
10.3. Creating Java Classes
10.3.1. Proxying Java Classes
10.3.2. Generating Java Classes
10.3.2.1. Ahead-of-Time Compilation
10.3.2.2. Basic gen-class Options
10.3.2.3. Defining Methods for the Generated Class
10.3.2.4. Adding State to the Generated Class
10.3.2.5. Adding Methods to the Generated Class
10.3.2.6. Adding Constructors and Factories
10.3.2.7. Exposing Superclass Members
10.3.2.8. Generating Command-Line Programs
10.3.2.9. Loading the Implementation
10.3.2.10. Namespace Declarations with gen-class
10.3.2.11. Simple Command-Line Program
10.4. Summary
11. Parallel Programming
11.1. Parallelism in Clojure
11.2. Agents
11.2.1. Agent Thread Pools
11.2.2. Agent Example
11.2.3. Concurrent Agent Performance
11.3. Concurrency Functions
11.3.1. Overhead and Performance
11.4. Futures and Promises
11.4.1. Futures
11.4.1.1. Controlling Futures
11.4.2. Promises
11.5. Java-based Threading
11.5.1. Creating a Thread
11.6. Summary
12. Macros and Metaprogramming
12.1. What Is Metaprogramming?
12.1.1. Code vs. Data
12.1.2. Homoiconicity
12.2. Macros
12.2.1. Working with Macros
12.2.1.1. Debugging Macros
12.2.2. Code Templating
12.2.2.1. Splicing Unquotes
12.2.3. Generating Symbols
12.2.4. When to Use Macros
12.2.5. Using Macros
12.2.5.1. Implementing a Control Structure
12.2.5.2. Implementing a Macro with Variadic Arguments
12.2.5.3. Implementing a Macro Using Recursion
12.2.6. Using Macros to Create DSLs
12.3. Summary
13. Datatypes and Protocols
13.1. Protocols
13.1.1. Protocols As Interfaces
13.2. Datatypes
13.3. Implementing Protocols and Interfaces
13.3.1. In-Line Methods
13.3.2. Extending Java Interfaces
13.3.3. Datatypes As Classes
13.4. Extending Protocols to Pre-Existing Types
13.4.1. Extending Java Classes and Interfaces
13.5. Reifying Anonymous Datatypes
13.6. Working with Datatypes and Protocols
13.6.1. A Complete Example
13.7. Advanced Datatypes
13.8. Summary
14. Performance
14.1. Profiling on the JVM
14.1.1. General Tips for Java Performance
14.1.2. Simple Profiling with Time
14.1.3. Using Java Profiling Tools
14.2. Memoization
14.3. Reflection and Type Hints
14.4. Working with Primitives
14.4.1. Loop Primitives
14.4.2. Unchecked Integer Arithmetic
14.4.3. Primitive Arrays
14.5. Transients
14.6. Var Lookups
14.7. Inlining
14.7.1. Macros and definline
14.8. Summary
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Copyright
Next
Next Chapter
About the Technical Reviewer
About the Authors
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset