List of Listings

Chapter 1. Clojure philosophy

Listing 1.1. A domain-specific language for embedding SQL queries in Clojure

Listing 1.2. Clojure’s polymorphic protocols

Listing 1.3. A simple chessboard representation in Clojure

Listing 1.4. Querying the squares of a chessboard

Listing 1.5. Using block-level encapsulation

Listing 1.6. Local encapsulation

Chapter 4. On scalars

Listing 4.1. Automatic promotion in Clojure

Listing 4.2. Illustrating the Patriot missile tragedy

Listing 4.3. Floating-point arithmetic isn’t associative or distributive.

Listing 4.4. Being rational preserves associativity and distributive natures.

Listing 4.5. Using a keyword as a function directive

Chapter 5. Composite data types

Listing 5.1. A function for finding the neighbors of a spot on a 2D matrix

Listing 5.2. First cut at our position function

Listing 5.3. An index function

Listing 5.4. Our final version of pos

Chapter 6. Being lazy and set in your ways

Listing 6.1. Short-circuiting if expression

Listing 6.2. Infinite sequences foster declarative solutions.

Listing 6.3. A lazy, tail-recursive quicksort implementation

Chapter 7. Functional programming

Listing 7.1. Named arguments in Clojure functions

Listing 7.2. Testing the slope function constraints

Listing 7.3. Menu constraints

Listing 7.4. A version of pow using mundane recursion

Listing 7.5. A version of pow using tail recursion, accumulator, and helper function

Listing 7.6. Using mutually recursive functions to implement a finite state machine

Listing 7.7. Factorial function using continuation-passing style

Listing 7.8. Continuation-passing style function generator

Listing 7.9. A straight-line h function to estimate remaining path cost

Listing 7.10. A g function used to calculate the cost of the path traversed so far

Listing 7.11. f function to calculate the estimated cost of the path (+ (g ...) (h ...))

Listing 7.12. The main A* algorithm

Listing 7.13. Running the A* algorithm on the Z World

Listing 7.14. The Shrubbery World

Listing 7.15. The bunny world

Chapter 8. Macros

Listing 8.1. An implementation of eval taking a local context

Listing 8.2. A Clojure Implementation of unless

Listing 8.3. Name capture in unless

Listing 8.4. Domain DSL’s underlying form

Listing 8.5. Exploring the domain DSL results

Listing 8.6. An XML transformation of the domain DSL structure

Listing 8.7. An example of anaphora and its weakness

Listing 8.8. An example of with-open

Listing 8.9. A more general template for with-open-like macros

Listing 8.10. The contract top-level macro

Listing 8.11. The contract auxiliary function build-contract

Listing 8.12. Composition of contract function and constrained function

Listing 8.13. Contract for multiple-arity functions

Chapter 9. Combining data and code

Listing 9.1. Namespace navigation

Listing 9.2. Persistent binary tree built of records

Listing 9.3. Complete implementations of FIXO for TreeNode and vector

Listing 9.4. Using a map to extend FIXO to TreeNode

Listing 9.5. Size-limited stack FIXO using reify

Listing 9.6. Method implementations in defrecord

Listing 9.7. Implementing map interfaces with deftype

Listing 9.8. A chess move record

Chapter 10. Java.next

Listing 10.1. A simple dynamic web service

Listing 10.2. Convenience functions for changing the web service message

Listing 10.3. The DynaFrame class namespace declaration

Listing 10.4. Simple GUI containers

Listing 10.5. A set of simple widgets

Listing 10.6. A more complex GUI example

Listing 10.7. Useful comparison functions

Listing 10.8. java.util.List conformance for sequences and seqs

Listing 10.9. An interface defining a sliceable object

Listing 10.10. A dummy reified ISliceable

Listing 10.11. Using a protocol to extend ISliceable

Listing 10.12. Extending strings along the Sliceable protocol

Listing 10.13. Throwing a compile-time exception

Chapter 11. Mutation

Listing 11.1. Using alter to update a Ref

Listing 11.2. How to make a Ref squirm

Listing 11.3. A resettable memoize function

Listing 11.4. A simple SafeArray protocol

Listing 11.5. An implementation of the SafeArray protocol using the locking macro

Listing 11.6. An implementation of the SafeArray protocol using ReentrantLock

Listing 11.7. Creating a future task to count word occurrences in a tweet

Listing 11.8. A macro to dispatch a sequence of futures

Listing 11.9. Counting string occurrences in Twitter feeds fetched in parallel

Listing 11.10. A macro to dispatch a sequence of promises across a number of threads

Listing 11.11. A macro for transforming a callback-based function to a blocking call

Chapter 12. Performance

Listing 12.1. A concatenation function using transients

Listing 12.2. A dechunkifying seq1 function

Listing 12.3. A protocol for caching

Listing 12.4. A basic cache type

Listing 12.5. A type implementing pluggable memoization

Listing 12.6. A function for applying pluggable memoization to a function

Listing 12.7. Using coercion to gain speed

Chapter 13. Clojure changes the way you think

Listing 13.1. Examples of Clojure’s relational algebra functions

Listing 13.2. A function for calculating compositional units of a base unit

Listing 13.3. A defunits-of macro

Listing 13.4. Macro to aid in mocking

Listing 13.5. Using with-redefs to create stubs

Listing 13.6. clojure.test as a partial specification

Listing 13.7. A macro to create spreadsheet-cell-like formulas

Listing 13.8. Handling nefarious tree nodes with exceptions

Listing 13.9. A modest debug console reader

Listing 13.10. Creating a map of the local context using &env

Listing 13.11. The implementation of a breakpoint macro

Listing 13.12. Using multiple breakpoints in function keys-apply

Listing 13.13. Using a breakpoint in a macro awhen

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.216.249