You are previewing Clojure for the Brave and True.
O'Reilly logo
Clojure for the Brave and True

Book Description

Clojure for the Brave and True is an epic introduction to functional programming with Clojure.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. About the Author
  5. About the Technical Reviewer
  6. Dedication
  7. Brief Contents
  8. Contents in Detail
  9. Foreword
  10. Acknowledgments
  11. Introduction
    1. Learning a New Programming Language: A Journey Through the Four Labyrinths
    2. How This Book Is Organized
      1. Part I: Environment Setup
      2. Part II: Language Fundamentals
      3. Part III: Advanced Topics
    3. The Code
    4. The Journey Begins!
  12. Part I: Environment Setup
    1. Chapter 1: Building, Running, and the REPL
      1. First Things First: What Is Clojure?
      2. Leiningen
        1. Creating a New Clojure Project
        2. Running the Clojure Project
        3. Building the Clojure Project
        4. Using the REPL
      3. Clojure Editors
      4. Summary
    2. Chapter 2: How to Use Emacs, an Excellent Clojure Editor
      1. Installation
      2. Configuration
      3. Emacs Escape Hatch
      4. Emacs Buffers
      5. Working with Files
      6. Key Bindings and Modes
        1. Emacs Is a Lisp Interpreter
        2. Modes
        3. Installing Packages
      7. Core Editing Terminology and Key Bindings
        1. Point
        2. Movement
        3. Selection with Regions
        4. Killing and the Kill Ring
        5. Editing and Help
      8. Using Emacs with Clojure
        1. Fire Up Your REPL!
        2. Interlude: Emacs Windows and Frames
        3. A Cornucopia of Useful Key Bindings
        4. How to Handle Errors
        5. Paredit
          1. Wrapping and Slurping
          2. Barfing
          3. Navigation
      9. Continue Learning
      10. Summary
  13. Part II: Language Fundamentals
    1. Chapter 3: Do Things: A Clojure Crash Course
      1. Syntax
        1. Forms
        2. Control Flow
          1. if
          2. do
          3. when
          4. nil, true, false, Truthiness, Equality, and Boolean Expressions
        3. Naming Values with def
      2. Data Structures
        1. Numbers
        2. Strings
        3. Maps
        4. Keywords
        5. Vectors
        6. Lists
        7. Sets
        8. Simplicity
      3. Functions
        1. Calling Functions
        2. Function Calls, Macro Calls, and Special Forms
        3. Defining Functions
          1. The Docstring
          2. Parameters and Arity
          3. Destructuring
          4. Function Body
          5. All Functions Are Created Equal
        4. Anonymous Functions
        5. Returning Functions
      4. Pulling It All Together
        1. The Shire’s Next Top Model
        2. let
        3. loop
        4. Regular Expressions
        5. Symmetrizer
        6. Better Symmetrizer with reduce
        7. Hobbit Violence
      5. Summary
      6. Exercises
    2. Chapter 4: Core Functions in Depth
      1. Programming to Abstractions
        1. Treating Lists, Vectors, Sets, and Maps as Sequences
        2. first, rest, and cons
        3. Abstraction Through Indirection
      2. Seq Function Examples
        1. map
        2. reduce
        3. take, drop, take-while, and drop-while
        4. filter and some
        5. sort and sort-by
        6. concat
      3. Lazy Seqs
        1. Demonstrating Lazy Seq Efficiency
        2. Infinite Sequences
      4. The Collection Abstraction
        1. into
        2. conj
      5. Function Functions
        1. apply
        2. partial
        3. complement
      6. A Vampire Data Analysis Program for the FWPD
      7. Summary
      8. Exercises
    3. Chapter 5: Functional Programming
      1. Pure Functions: What and Why
        1. Pure Functions Are Referentially Transparent
        2. Pure Functions Have No Side Effects
      2. Living with Immutable Data Structures
        1. Recursion Instead of for/while
        2. Function Composition Instead of Attribute Mutation
      3. Cool Things to Do with Pure Functions
        1. comp
        2. memoize
      4. Peg Thing
        1. Playing
        2. Code Organization
        3. Creating the Board
        4. Moving Pegs
        5. Rendering and Printing the Board
        6. Player Interaction
      5. Summary
      6. Exercises
    4. Chapter 6: Organizing Your Project: A Librarian’s Tale
      1. Your Project as a Library
      2. Storing Objects with def
      3. Creating and Switching to Namespaces
        1. refer
        2. alias
      4. Real Project Organization
        1. The Relationship Between File Paths and Namespace Names
        2. Requiring and Using Namespaces
        3. The ns Macro
      5. To Catch a Burglar
      6. Summary
    5. Chapter 7: Clojure Alchemy: Reading, Evaluation, and Macros
      1. An Overview of Clojure’s Evaluation Model
      2. The Reader
        1. Reading
        2. Reader Macros
      3. The Evaluator
        1. These Things Evaluate to Themselves
        2. Symbols
        3. Lists
          1. Function Calls
          2. Special Forms
        4. Macros
        5. Syntactic Abstraction and the -> Macro
      4. Summary
      5. Exercises
    6. Chapter 8: Writing Macros
      1. Macros Are Essential
      2. Anatomy of a Macro
      3. Building Lists for Evaluation
        1. Distinguishing Symbols and Values
        2. Simple Quoting
        3. Syntax Quoting
      4. Using Syntax Quoting in a Macro
      5. Refactoring a Macro and Unquote Splicing
      6. Things to Watch Out For
        1. Variable Capture
        2. Double Evaluation
        3. Macros All the Way Down
      7. Brews for the Brave and True
        1. Validation Functions
        2. if-valid
      8. Summary
      9. Exercises
  14. Part III: Advanced Topics
    1. Chapter 9: The Sacred Art of Concurrent and Parallel Programming
      1. Concurrency and Parallelism Concepts
        1. Managing Multiple Tasks vs. Executing Tasks Simultaneously
        2. Blocking and Asynchronous Tasks
        3. Concurrent Programming and Parallel Programming
      2. Clojure Implementation: JVM Threads
        1. What’s a Thread?
        2. The Three Goblins: Reference Cells, Mutual Exclusion, and Dwarven Berserkers
      3. Futures, Delays, and Promises
        1. Futures
        2. Delays
        3. Promises
        4. Rolling Your Own Queue
      4. Summary
      5. Exercises
    2. Chapter 10: Clojure Metaphysics: Atoms, Refs, Vars, and Cuddle Zombies
      1. Object-Oriented Metaphysics
      2. Clojure Metaphysics
      3. Atoms
      4. Watches and Validators
        1. Watches
        2. Validators
      5. Refs
        1. Modeling Sock Transfers
        2. commute
      6. Vars
        1. Dynamic Binding
          1. Creating and Binding Dynamic Vars
          2. Dynamic Var Uses
          3. Per-Thread Binding
        2. Altering the Var Root
      7. Stateless Concurrency and Parallelism with pmap
      8. Summary
      9. Exercises
    3. Chapter 11: Mastering Concurrent Processes with core.async
      1. Getting Started with Processes
        1. Buffering
        2. Blocking and Parking
        3. thread
      2. The Hot Dog Machine Process You’ve Been Longing For
      3. alts!!
      4. Queues
      5. Escape Callback Hell with Process Pipelines
      6. Additional Resources
      7. Summary
    4. Chapter 12: Working with the JVM
      1. The JVM
      2. Writing, Compiling, and Running a Java Program
        1. Object-Oriented Programming in the World’s Tiniest Nutshell
        2. Ahoy, World
      3. Packages and Imports
      4. JAR Files
      5. clojure.jar
      6. Clojure App JARs
      7. Java Interop
        1. Interop Syntax
        2. Creating and Mutating Objects
        3. Importing
      8. Commonly Used Java Classes
        1. The System Class
        2. The Date Class
      9. Files and Input/Output
      10. Resources
      11. Summary
    5. Chapter 13: Creating and Extending Abstractions with Multimethods, Protocols, and Records
      1. Polymorphism
        1. Multimethods
        2. Protocols
      2. Records
      3. Further Study
      4. Summary
      5. Exercises
  15. Appendix A: Building and Developing with Leiningen
    1. The Artifact Ecosystem
      1. Identification
      2. Dependencies
      3. Plug-Ins
    2. Summary
  16. Appendix B: Boot, the Fancy Clojure Build Framework
    1. Boot’s Abstractions
    2. Tasks
    3. The REPL
    4. Composition and Coordination
      1. Handlers and Middleware
      2. Tasks Are Middleware Factories
    5. Filesets
    6. Next Steps
  17. Farewell!
  18. Index
  19. Footnote
    1. Chapter 2: How to Use Emacs, an Excellent Clojure Editor
  20. Resources
  21. Join the Ranks of Noble Clojurists