
Write an anonymous function (a "function literal")
to return the third value in a list. You may assume that the list has at least three elements.
(fn [x] (first (rest (rest x))))
or
(fn [x] (nth x 2))

Write a function named
neg
to return the first negative number in a list of numbers. You may assume that the list contains some negative numbers.
(defn neg [lst]
(if (< (first lst) 0)
(first lst)
(neg (rest lst)) ) )
 Write an anonymous function that, given a positive integer
N
, will return a list or sequence (either one) of the integers 1
through N
, inclusive.
(fn [n] (take n (iterate inc 1)))
or
(fn [n] (range 1 (inc n)))
 Give the function defined in the previous question the name
countto
. Then use countto
to write an expression whose value is a list of squares of the numbers 1
through 100
. That is, it returns [1 4 9 16 ... 10000]
.
(def countto (fn [n] (range 1 (inc n))))
(map (fn [x] (* x x)) (countto 100))
or
(for [x (countto 100)] (* x x))
 Define a function
nonmult3
with argument N
which returns true if N
is not a multiple of 3
. Reminder: Clojure has mod
and not
functions that you can use.
(defn nonmult3 [x] (not (zero? (mod x 3))))
 Use the previously defined functions to compute the product of the numbers
1
through 25
that are not multiples of 3
.
(reduce * (filter nonmult3 (countto 25)))
 Briefly, what does it mean to say that "a transaction is atomic"?
Viewed from another thread, either all the actions in the transaction have completed, or none have.
 Briefly, what is a reference varable (
ref
)?
A mutable pointer to immutable data.
 The real problem with the Java approach to concurrency is that
___________________________ + ___________________________ = ___________________________.
(fill in the blanks).
 Write a tailrecursive function named
sum
to add up all the numbers in a list of numbers. Hint: Define sum
to have two parameters, and use one of them as an "accumulator."