Menu

- Chapter 1 Distilled
- Introduction
- 1.1 - The Elements Of Programming
- Expressions
- Naming and the Environment
- Evaluating Combinations
- Defining New Functions
- The Substitution Model
- Exercises
- Predicates
- Conditional Expressions
- Example: Newtonâ€™s Method
- Functions as Black-Box Abstractions
- 1.2 - Procedures and the Processes They Generate
- Linear Recursion and Iteration
- Tree Recursion
- Orders of Growth
- Exponentiation
- Example: Testing For Primality
- 1.3 Higher Order Functions
- Project - Blackjack

- Chapter 2 Distilled
- Introduction
- Data Abstraction
- Everything From Nothing
- Abstractions In Clojure
- Clojure's Data Structures
- Data Abstraction, Revisited
- Escher
- Project - Escher
- Symbolic Data
- Representing Sets
- Huffman Encoding Trees
- Zippers

LISPs all have a so-called Read-Eval-Print-Loop where you type an expression and the interpreter responds by displaying the result of its evaluating that expression.

You can use Try Clojure to get a REPL (you may also
like to do the intro there, start it by typing `next`

)

Leiningen is the easiest way to manage Clojure projects, it also provides a repl

Run `lein repl`

from the commandline after you have
installed Leiningen

Some things simply evaluate to themselves:

```
> 3
3
```

```
> "Hello"
"Hello"
```

```
> :foo
:foo
```

```
> true
true
> false
false
```

```
> \c
\c
```

If you try to lookup a name that does not exist then you get an error

```
> undefined
CompilerException java.lang.RuntimeException:
Unable to resolve symbol: undefined in this context
```

```
> (+ 2 4)
6
```

Expressions such as these, formed by delimiting a list of expressions within
parentheses in order to denote function application, are called *combinations*.
The leftmost element in the list is called the *operator*, and the other elements
are called *operands*. The value of a combination is obtained by applying the
function specified by the operator to the arguments that are the values of the
operands.

The convention of placing the operator to the left of the operands is known as prefix notation, and it may be somewhat confusing at first because it departs significantly from the customary mathematical convention. Prefix notation has several advantages, however. One of them is that it can accommodate functions that may take an arbitrary number of arguments, as in the following examples:

```
> (* 2 3 4)
24
```

```
> (/ 45 5 3)
3
```

Prefix notation also extends in a straightforward way to allow combinations to be nested, that is, to have combinations whose elements are themselves combinations:

```
> (+ (* 3 5) (- 10 6))
19
```

Sometimes reading complex s-expressions can be made easier by lining them up

```
(+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6))
```

```
(+ (* 3
(+ (* 2 4)
(+ 3 5)))
(+ (- 10 7)
6))
```