diff src/reverse_sentence.clj @ 0:307a81e46071 tip

initial committ
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 01:17:49 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/reverse_sentence.clj	Tue Oct 18 01:17:49 2011 -0700
     1.3 @@ -0,0 +1,28 @@
     1.4 +(ns coderloop.reverse-sentence
     1.5 +  (:refer-clojure :only [])
     1.6 +  (:require rlm.ns-rlm rlm.light-base))
     1.7 +(rlm.ns-rlm/ns-clone rlm.light-base)
     1.8 +
     1.9 +
    1.10 +(undef partition)
    1.11 +(use '[clojure.contrib [string :only [partition]]])
    1.12 +(use '[clojure [string :only [blank?]]])
    1.13 +
    1.14 +(defn reverse-line [s]
    1.15 +  (apply str
    1.16 +	 (flatten 
    1.17 +	  (map #(if (re-matches #"\w" (str (first %))) (reverse %) %)
    1.18 +	       (filter (comp not (partial = ""))
    1.19 +		       (partition #"\w+" s))))))
    1.20 +
    1.21 +
    1.22 +(defn reverse-file [file]
    1.23 +  (doall
    1.24 +   (map println
    1.25 +	(map reverse-line
    1.26 +	     (read-lines file)))))
    1.27 +
    1.28 +
    1.29 +(if (command-line?)
    1.30 +  (reverse-file (first *command-line-args*)))
    1.31 +