From: slack Date: Tue, 8 Dec 2009 21:01:43 +0000 (+0100) Subject: added an example X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=1e9ef7b5931cca9a45f1b2b70045d8e932d11ec6;p=clojure-slides.git added an example --- diff --git a/clojure-slides.xhtml b/clojure-slides.xhtml index 157b95c..9ced9ae 100755 --- a/clojure-slides.xhtml +++ b/clojure-slides.xhtml @@ -170,11 +170,26 @@

Entonces... ¿qué pinta tiene un programa?

+ + (ns wordcount (:gen-class)
+   (:use clojure.contrib.str-utils))
+
+ (defn num-lines [text] (count (re-split #"\n" text)))
+ (defn num-words [text] (count (re-split #"\s+" text)))
+ (defn num-characters [text] (count text))
+
+ (defn -main [file]
+   (let [text (slurp file)]
+     (println (num-lines text) (num-words text) (num-characters text))))
+     
+
+
+

Cool stuff

-

Multimethods, macros, regexes, interop, seqs... +

Multimethods, macros, regexes, interop, seqs...