Mercurial > coderloop
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:307a81e46071 |
---|---|
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) | |
5 | |
6 | |
7 (undef partition) | |
8 (use '[clojure.contrib [string :only [partition]]]) | |
9 (use '[clojure [string :only [blank?]]]) | |
10 | |
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)))))) | |
17 | |
18 | |
19 (defn reverse-file [file] | |
20 (doall | |
21 (map println | |
22 (map reverse-line | |
23 (read-lines file))))) | |
24 | |
25 | |
26 (if (command-line?) | |
27 (reverse-file (first *command-line-args*))) | |
28 |