Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit; Chapter 1, done!

  • Loading branch information...
commit c3acd1dea8ff2f45133d34e1a1bc1590ec485656 0 parents
Steven Harman authored
10 .gitignore
... ... @@ -0,0 +1,10 @@
  1 +/target
  2 +/lib
  3 +/classes
  4 +/checkouts
  5 +pom.xml
  6 +*.jar
  7 +*.class
  8 +.lein-deps-sum
  9 +.lein-failures
  10 +.lein-plugins
12 README.md
Source Rendered
... ... @@ -0,0 +1,12 @@
  1 +# fp-oo-exercises
  2 +
  3 +A collection of Clojure snippets from my trip through @marick's "Functional
  4 +Programming for Object-Oriented Programmers" as part of the @bignerdranch book
  5 +club.
  6 +
  7 +## License
  8 +
  9 +Copyright © 2012 Steven Harman
  10 +
  11 +Distributed under the WTFPL. That is to say, it's free; if it breaks, feel
  12 +free to keep both parts.
3  doc/intro.md
Source Rendered
... ... @@ -0,0 +1,3 @@
  1 +# Introduction to fp-oo-exercises
  2 +
  3 +TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
5 project.clj
... ... @@ -0,0 +1,5 @@
  1 +(defproject fp-oo-exercises "0.1.0-SNAPSHOT"
  2 + :description "Steven Harman's first trip into Clojure"
  3 + :license {:name "WTFPL"
  4 + :url "http://sam.zoy.org/wtfpl/"}
  5 + :dependencies [[org.clojure/clojure "1.4.0"]])
6 src/fp_oo_exercises/core.clj
... ... @@ -0,0 +1,6 @@
  1 +(ns fp-oo-exercises.core)
  2 +
  3 +(defn foo
  4 + "I don't do a whole lot."
  5 + [x]
  6 + (println x "Hello, World!"))
49 src/fp_oo_exercises/just-enough-clojure.clj
... ... @@ -0,0 +1,49 @@
  1 +;; Exercise 1
  2 +(def second (fn [list] (first (rest list))))
  3 +
  4 +;; Exercise 2
  5 +(def third (fn [list] (nth list 2)))
  6 +
  7 +(def third-2 (fn [list] (second (rest list))))
  8 +
  9 +;; Exercise 3
  10 +(def add-squares
  11 + (fn [& args]
  12 + (apply + (map
  13 + (fn [n] (* n n))
  14 + args))))
  15 +
  16 +;; Exercise 4
  17 +(def factorial
  18 + (fn [n]
  19 + (apply * (range 1 (inc n)))))
  20 +
  21 +;; Exercise 5
  22 +;; Lots of playing around in repl...
  23 +
  24 +;; Exercise 6
  25 +(def prefix-of?
  26 + (fn [candidate sequence]
  27 + (= (take (count candidate) sequence)
  28 + candidate)))
  29 +
  30 +;; Exercise 7
  31 +(def tails
  32 + (fn [seq]
  33 + (map drop
  34 + (range 0 (inc (count seq)))
  35 + (repeat (inc (count seq)) seq))))
  36 +
  37 +;; Exercise 8
  38 +(def puzzle
  39 + (fn [list] (list list)))
  40 +
  41 +;; user => (puzzle '(1 2 3))
  42 +;; ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn user/puzzle (NO_SOURCE_FILE:1))
  43 +;;
  44 +;; When the argument is substituted into the expanded function we get
  45 +;; ((1 2 3) (1 2 3))
  46 +;;
  47 +;; And the error is complaining about the first list NOT being something that
  48 +;; could be evaluted to a function, as is expected.
  49 +
7 test/fp_oo_exercises/core_test.clj
... ... @@ -0,0 +1,7 @@
  1 +(ns fp-oo-exercises.core-test
  2 + (:use clojure.test
  3 + fp-oo-exercises.core))
  4 +
  5 +(deftest a-test
  6 + (testing "FIXME, I fail."
  7 + (is (= 0 1))))

0 comments on commit c3acd1d

Please sign in to comment.
Something went wrong with that request. Please try again.