Permalink
Browse files

completed chapter 5

added license and credits
  • Loading branch information...
1 parent b956c0e commit f393905f6862910ff318d7846e32d4c853e286b7 @stuarthalloway committed Sep 15, 2008
Showing with 122 additions and 1 deletion.
  1. +20 −0 LICENSE
  2. +35 −0 PRACTICAL-CL-LICENSE
  3. +34 −0 README
  4. +32 −0 chap_05.clj
  5. +1 −1 user.clj
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Relevance, Inc. (http://thinkrelevance.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,35 @@
+(Practical-cl-clojure is a port of an existing library, so I am
+including the license from the original library below. To download
+the original, head over to http://gigamonkeys.com. --Stu)
+
+ORIGINAL LICENSE FOLLOWS:
+
+Copyright (c) 2005, Peter Seibel All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the Peter Seibel nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
34 README
@@ -0,0 +1,34 @@
+PRACTICAL-CL-CLOJURE
+----------------------
+A port of selected examples from Practical Common Lisp to Clojure.
+The purpose of this port is to explore the intersection between
+Lisp and Clojure's signature features: access to the JVM and a
+functional programming style base on immutable collections.
+
+
+WHAT YOU SHOULD DO FIRST
+------------------------
+Read Practical Common Lisp. It's great. Buy a copy.
+http://gigamonkeys.com/book/
+
+
+THEN...
+----------------------
+Get yourself some Clojure (http://clojure.org) and take
+a look at the code in this project.
+
+
+LICENSES
+----------------------
+Practical-cl-clojure is licensed under an MIT license,
+see LICENSE.
+
+Peter Seibel, the author of Practical Common Lisp, wrote all
+the code that inspired this port. The original is available at
+http://gigamonkeys.com, and I have reproduced that license
+and copyright in PRACTICAL-CL-LICENSE.
+
+Stuart Halloway
+stu@thinkrelevance.com
+
+
View
@@ -9,3 +9,35 @@
(defn make-rectangle
([width] (make-rectangle width width))
([width height] {:width width :height height}))
+
+; not obvious how to get the var-supplied idiom from CL
+(defn which-args-supplied [{:keys [a b c] :as all :or {a 2 b 3}}]
+ (let [c-supplied (contains? all :c)]
+ (list a b c c-supplied)))
+
+; can't write return-from, because defn does not wrap in named entity
+
+; do this instead
+(defn pair-with-product-greater-than [n]
+ (take 1 (for [i (range 10) j (range 10) :when (> (* i j) n)] [i j])))
+
+; using dotimes instead of repeat from cl
+(defn plot [f min max step]
+ (doseq i (range min max step)
+ (dotimes _ (apply f [i]) (print "*"))
+ (println)))
+
+(defn stars [ct]
+ (apply str (take ct (repeat "*"))))
+
+; more idiomatic ?
+(defn plot [f min max step]
+ (doseq i (range min max step)
+ (print (stars (apply f [i])))
+ (println)))
+
+; anonymous function examples
+; (plot (fn [x] (* x 2)) 1 10)
+
+; shorter (like Groovy's 'it')
+; (plot #(* 2 %) 1 10 1)
View
@@ -1,4 +1,4 @@
(println "custom settings loaded...")
(. clojure.lang.RT (loadResourceScript "clojure/contrib/lib/lib.clj"))
(clojure.contrib.lib/use '(clojure.contrib test-is))
-(defn f [test] (load-file test) (run-tests))
+

0 comments on commit f393905

Please sign in to comment.