Mercurial > rlm
annotate src/rlm/dylan-reverse-seq.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children |
rev | line source |
---|---|
rlm@0 | 1 (ns coderloop.reverse-sequence) |
rlm@0 | 2 (use 'clojure.contrib.str-utils) |
rlm@0 | 3 ;;(use 'rlm.shell-inspect) |
rlm@0 | 4 |
rlm@0 | 5 (defn extension[f ip op] (fn[x](if (= x ip) op (f x)))) |
rlm@0 | 6 |
rlm@0 | 7 (let[ |
rlm@0 | 8 ;;*command-line-args* (list "/home/ocsenave/testfile.txt") |
rlm@0 | 9 pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\r\n" (slurp(first *command-line-args*))))) |
rlm@0 | 10 predecessor (reduce #(extension %1 (second %2)(first %2)) (fn[x]nil) pairs) |
rlm@0 | 11 terminus (first(remove(set(map first pairs))(map second pairs))) |
rlm@0 | 12 ] |
rlm@0 | 13 (defn lineage[x](if(nil? x)nil (cons x(lineage (predecessor x))))) |
rlm@0 | 14 (print (str-join "\n" (lineage terminus))) |
rlm@0 | 15 ) |
rlm@0 | 16 |
rlm@0 | 17 |
rlm@0 | 18 ;;(if (command-line?) |
rlm@0 | 19 ;; (do-something-to *command-line-args*)) |
rlm@0 | 20 |