Etudes for ClojureScript

Book description

A short composition that provides practice material for a particular musical skill is called an étude. In this hands-on book, you’ll find more than 30 études to help you practice ClojureScript skills for specific programming areas, ranging from functions and variables to asynchronous processing. Each of these small projects includes a description of a program that you will compose (write) in ClojureScript.

Though not as difficult as their musical counterparts, these programming études will help you stretch beyond the material and examples that you find in most ClojureScript books or online references. One chapter features études for an open-ended project that will help you put together what you’ve learned. Solutions to each étude are revealed in the appendix.

Programming areas include:

  • Working with functions and variables with def and let
  • Interacting with JavaScript and web pages, using several libraries
  • Lists, vectors, and higher-order map, filter, and reduce functions
  • Data mapping with ClojureScript
  • Using different ClojureScript libraries to program with React
  • Adding, subtracting, multiplying, and dividing rational and complex numbers with defprotocol and defrecord
  • Asynchronous processing with core.async

J. David Eisenberg is a programmer and instructor in San Jose, California. He’s developed courses for CSS, JavaScript, CGI, and XML, and teaches Computer Information Technology courses at Evergreen Valley College. David has written Études for Erlang (O’Reilly), Let’s Read Hiragana (Eisenberg Consulting), and SVG Essentials (O’Reilly).

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. What’s an Étude?
    2. What Are Études for ClojureScript?
    3. Acknowledgments
  2. 1. Functions and Variables
    1. Étude 1-1: Defining a Function in the REPL
    2. Étude 1-2: Defining Functions in a Source File
    3. Étude 1-3: Using def
    4. Étude 1-4: Using let
    5. Étude 1-5: More Practice with def and let
  3. 2. Interacting with JavaScript and Web Pages
    1. Étude 2-1: Direct Use of JavaScript
      1. Invoking Methods
      2. Accessing Properties
      3. Creating JavaScript Objects
      4. Listening for Events
    2. Étude 2-2: Using Google Closure
      1. Putting Google Closure into Your Project
      2. Using Google Closure to Access the DOM
      3. Using Google Closure to Handle Events
    3. Étude 2-3: Using dommy
      1. Putting dommy into Your Project
      2. Using dommy to Access the DOM
      3. Using dommy to Handle Events
    4. Étude 2-4: Using Domina
      1. Putting Domina into Your Project
      2. Using Domina to Access the DOM
      3. Using Domina to Handle Events
    5. Étude 2-5: Using Enfocus
      1. Putting Enfocus into Your Project
      2. Using Enfocus to Access the DOM
      3. Using Enfocus to Handle Events
  4. 3. Lists, Vectors, and Higher-Order Functions
    1. Étude 3-1: Move the Zeros
    2. Étude 3-2: More List Manipulation
    3. Étude 3-3: Basic Statistics
    4. Étude 3-4: Basic Statistics in a Web Page
    5. Étude 3-5: Dental Hygiene
    6. Étude 3-6: Random Numbers—Generating a Vector of Vectors
    7. Étude 3-7: Monthly Daylight
  5. 4. Maps
    1. Étude 4-1: Condiments
      1. Parsing XML
      2. Command-line Arguments
      3. Mutually Recursive Functions
    2. Étude 4-2: Condiment Server
      1. Setting Up Express
      2. Generating HTML from ClojureScript
      3. Putting the Étude Together
    3. Étude 4-3: Maps—Frequency Table
      1. Reading the CSV File
    4. Étude 4-4: Complex Maps—Cross-Tabulation
    5. Étude 4-5: Cross-Tabulation Server
  6. 5. Programming with React
    1. Étude 5-1: Reactive Programming with Quiescent
      1. Hints
    2. Étude 5-2: Reactive Programming with Reagent
      1. Hints
  7. 6. Interlude: Room Usage Project
    1. Étude 6-1: Build the Data Structure
    2. Étude 6-2: Visualizing the Data (Version 1)
    3. Étude 6-3: Visualizing the Data (Version 2)
  8. 7. Records and Protocols
    1. Étude 7-1: Rational Numbers
    2. Étude 7-2: Complex Numbers
    3. Étude 7-3: Writing Tests
  9. 8. Asynchronous Processing
    1. Étude 8-1: A Card Game
      1. The Art of War
      2. War: What Is It Good For?
      3. Pay Now or Pay Later
      4. The Design
      5. Messages Are Asynchronous
      6. Representing the Deck
  10. A. Solutions
    1. Solution 1-2
    2. Solution 1-3
    3. Solution 1-4
    4. Solution 1-5
    5. Solution 2-1
    6. Solution 2-2
    7. Solution 2-3
    8. Solution 2-4
    9. Solution 2-5
    10. Solution 3-1
    11. Solution 3-2
    12. Solution 3-3
    13. Solution 3-4
    14. Solution 3-5
    15. Solution 3-6
    16. Solution 3-7
    17. Solution 4-1
    18. Solution 4-2A
    19. Solution 4-2B
    20. Solution 4-3
      1. File cljs_made_easy/line_seq.clj
      2. File cljs_made_easy/line_seq.cljs
      3. File frequency/core.cljs
    21. Solution 4-4
    22. Solution 4-5
    23. Solution 5-1
    24. Solution 5-2
    25. Solution 6-1
      1. File building_usage/src/roster.cljs
      2. File building_usage/src/utils.cljs
    26. Solution 6-2
      1. File core.cljs
      2. File index.html
    27. Solution 6-3
      1. File core.cljs
      2. File index.html
    28. Solution 7-1
    29. Solution 7-2
    30. Solution 7-3
    31. Sample core.async Program 1
    32. Sample core.async Program 2
    33. Solution 8-1
      1. File core.cljs
      2. File utils.cljs
  11. B. Setting Up Your ClojureScript Environment
    1. Setting Up ClojureScript
      1. Getting Java
      2. Getting Clojure and ClojureScript
      3. Creating a ClojureScript Project
      4. ClojureScript File src/sample_project/core.cljs
      5. File index.html
      6. File build.clj
      7. File release.clj
      8. File repl.clj
      9. File watch.clj
      10. Getting a Text Editor
  12. C. Creating a ClojureScript Project with Leiningen
    1. The mies Template
    2. The figwheel Template
  13. D. ClojureScript on the Server
    1. ClojureScript on the Server
      1. Getting Node.js
      2. Creating a ClojureScript/Node.js Project
      3. ClojureScript File src/node_project/core.cljs
      4. File node.clj
      5. File node_repl.clj
      6. Using Node.js Modules

Product information

  • Title: Etudes for ClojureScript
  • Author(s): J. David Eisenberg
  • Release date: November 2015
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491934890