view 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 source
1 (ns coderloop.reverse-sentence
2 (:refer-clojure :only [])
3 (:require rlm.ns-rlm rlm.light-base))
4 (rlm.ns-rlm/ns-clone rlm.light-base)
7 (undef partition)
8 (use '[clojure.contrib [string :only [partition]]])
9 (use '[clojure [string :only [blank?]]])
11 (defn reverse-line [s]
12 (apply str
13 (flatten
14 (map #(if (re-matches #"\w" (str (first %))) (reverse %) %)
15 (filter (comp not (partial = ""))
16 (partition #"\w+" s))))))
19 (defn reverse-file [file]
20 (doall
21 (map println
22 (map reverse-line
23 (read-lines file)))))
26 (if (command-line?)
27 (reverse-file (first *command-line-args*)))