[Cs254f11] code from class

Lee Spector lspector at hampshire.edu
Wed Oct 5 14:58:54 EDT 2011


With no context but I hope it will be helpful to somebody:


(repeatedly 5 (fn [] [(rand) (rand) (rand)]))

(defn randvec
 []
 [(rand) (rand) (rand)])

(repeatedly 5 rand)

(repeatedly 5 randvec)

(defn randvecn
 [n]
 (vec (repeatedly n rand)))

(repeatedly 3 (fn [x y] (randvecn 5)))

#(+ %1 %2 3)

(def v [3 4 5 6 7 4 3 5 6 3 34 583 3498])

(map even? v)

(map (fn [x] (* x 100)) v)

(map #(* % 100) v)

(filter even? v)

(filter #(zero? (mod % 3)) v)

(defn call-shuffled [f & args]
 (apply f (shuffle args)))

(call-shuffled / 2 4)

(def foo '(1 2 3))

(apply + foo)

(time (+ 1 2))


--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list