Clojure Recipes

Book description

“There’s something for everyone here. . . . You can pick up and read this book and build an industry-standard system in a weekend: It has everything you need to get started with a new project. I also found it helpful in reviewing the structure of existing projects.” —Timothy Pratley, developer 

Developers are discovering the exceptional power of Clojure’s functional programming model to quickly solve problems in domains ranging from social networking to Big Data. Clojure is fast and efficient—ideal for rapid prototyping and lean development. And it is highly expressive and extremely extensible, which makes Clojure one of today’s leading tools for software innovation. Since it targets the Java Virtual Machine, Clojure also leverages the Java platform’s maturity and enormous ecosystem.

Clojure Recipes is a wide-ranging, up-to-date “code recipe book” for this increasingly popular language. With practical and self-contained examples, author Julian Gamble illuminates Clojure’s key features and best practices, showing how to solve real-world problems one step at a time. Focusing on Clojure 1.7 and higher, Gamble fully reflects recent enhancements that ensure you’re getting the most up-to-date code for your project.

Gamble first walks you through the essential steps required to set up your Clojure development environment, from setting up the Leiningen build tool to packaging Clojure for Java EE environments. He then shows you how to build both basic and advanced REST servers, before turning to a wide range of increasingly sophisticated applications.

In this book you will find

  • Innovative Clojure code for diverse web, security, administration, and development tasks, from log reading and app monitoring to software testing

  • Detailed instructions for using concurrency primitives, writing new DSLs, simplifying cloud database development, and more

  • “Learn by doing” projects, which offer practical experience with Clojurescript, Storm, Pedestal, Datomic, and other advanced tools

  • Coverage of using Clojure with Cascalog 2.0 to write complex Hadoop queries with minimal code 

  • The breadth and quality of Gamble’s examples make Clojure Recipes uniquely valuable both to developers who are exploring Clojure for the first time and to those already using it in production.

    Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Contents
    6. Preface
      1. Who This Book Is For
      2. What This Book Is Not
      3. What This Book Is About
      4. Why Clojure?
      5. Coding Conventions Used in This Book
        1. Errata
    7. About the Author
    8. 1. Starting Your Project with Leiningen
      1. Assumptions
      2. Benefits
      3. The Recipe—Windows
      4. The Recipe—Mac
      5. Conclusion
      6. Postscript—Setting Up a JDK on a Mac
      7. Postscript—Setting Up a JDK on Windows
    9. 2. Packaging Clojure for a Java EE Environment
      1. Assumptions
      2. Benefits
      3. The Recipe—Common
      4. Conclusion
      5. Postscript—Setting Up Tomcat on a Mac
      6. Postscript—Setting Up Tomcat on Windows
    10. 3. Creating a REST Server in Compojure
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    11. 4. Creating a REST Server with Liberator
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Context
        1. Origins
        2. REST Hypermedia
      7. Conclusion
    12. 5. A REST Client in ClojureScript
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    13. 6. A Simple JSON Server
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    14. 7. A Simple Server Using the Pedestal Framework
      1. Assumptions
      2. Benefits
      3. Context
      4. The Recipe—Code
      5. Testing the Solution
      6. Notes on the Recipe
      7. Conclusion
    15. 8. A Stock Ticker on the Pedestal Framework Server
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    16. 9. Simplifying Logging with a Macro
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    17. 10. Extending the Compiler with a Macro
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    18. 11. Simplifying Datomic Syntax by Writing a DSL
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
        1. Testing Create Schema
        2. Testing Add Datom
        3. Testing Create Nested Schema
        4. Testing Add Nested Datom
      5. Notes on the Recipe
        1. create.clj
        2. create_test.clj
        3. add.clj
        4. add_test.clj
        5. create_nested.clj
        6. create_nested_test.clj
        7. add_nested.clj
        8. add_nested_test.clj
      6. Conclusion
    19. 12. Reading the SASS DSL and Generating CSS with Clojure Zippers
      1. Assumptions
      2. Benefits
      3. Outline—Features of SASS
      4. The Recipe—Code
      5. Testing the Solution
      6. Notes on the Recipe
      7. Conclusion
    20. 13. Introduction to Cascalog
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    21. 14. Cascalog and Hadoop
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Conclusion
      6. Postscript—Setting Up Hadoop on a Mac
      7. Postscript—Setting Up Hadoop on a Windows Machine
    22. 15. Loading a Data File into Cascalog
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Conclusion
    23. 16. Writing Out a Data File with Cascalog
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    24. 17. Cascalog and Structured Data
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Solution
      6. Conclusion
    25. 18. Loading Custom Data Formats into Cascalog
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Solution
      6. Conclusion
    26. 19. Connecting to Datomic from Your Application
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
        1. Getting Set Up
        2. Connecting to Datomic in the Shell
        3. Loading Schema and Data
        4. Connecting to Datomic from Clojure
        5. Connecting to Datomic from Java
        6. Connecting to Datomic from a REST Client
      4. Conclusion
    27. 20. Getting Started with Storm
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    28. 21. Getting Started with JMS in Clojure
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    29. 22. Integrating Storm and JMS
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    30. 23. A CSV Reader
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    31. 24. Detecting Errors with a Log Monitoring Application
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Solution
      5. Notes on the Recipe
      6. Conclusion
    32. 25. Bundling Clojure as an Ant Plug-in
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
      7. Postscript—Installing Ant on a Mac
    33. 26. Bundling Clojure as a Maven Plug-in
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    34. 27. Integrating Clojure by Scripting Web Tests
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    35. 28. Monitoring Availability with a Website Status Checker
      1. Assumptions
      2. Benefits
      3. The Recipe—Code
      4. Testing the Recipe
      5. Notes on the Recipe
      6. Conclusion
    36. A. Debugging Macros
      1. Assumptions
      2. Benefits
      3. The Recipe
        1. A Simple Approach—Expansion-Time and Evaluation-Time stdout
        2. Some Macro Helper Functions
        3. Read and Evaluate—A More Developed Mental Model
        4. Reading
        5. Evaluating
      4. Conclusion
    37. Index
    38. Code Snippets

    Product information

    • Title: Clojure Recipes
    • Author(s): Julian Gamble
    • Release date: October 2015
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780133430097