1st Clojure script and...

  • Follow


.... was wondering if some of you more experienced
folks could critique my effort if so compelled.

Thanks!


; Clojure TOPIC database parser - Topcat Software LLC. 2011
;
; nix invocation: java -cp clojure.jar clojure.main topic.clj < file.input
; $@
; win invocation: java -cp clojure.jar clojure.main topic.clj < file.input
; $%


(ns topic (require [clojure.string :as s]))

; ---------------------------------------------------------------------------

(defn indices

"TOPIC database: prints indices to stdout"

    ([] (loop [line (read-line)]
            (when line
                (when (and (not= "" (s/trim line))
                        (not= "\t" (subs line 0 1)))
                    (println line))
        (recur (read-line))))))

; ---------------------------------------------------------------------------

(defn load-block

"TOPIC database: prints associated blocks to stdout"

    ([tag]
        (let [STATE (atom 0)
               rx (re-pattern (str "(?i)" tag "[[:space:]]*(,|$)"))]
            (loop [line (read-line)]
                (when line
                    (when (and (not= "" (s/trim line))
                            (not= "\t" (subs line 0 1)))
                        (if (re-find  rx line)
                            (reset! STATE 1)
                            (reset! STATE 0)))
                    (if (= @STATE 1)
                        (println line))
            (recur (read-line)))))))

; ---------------------------------------------------------------------------

(defn blurb ([]

"TOPIC database: prints syntax panel to stdout"

(println "

multi-line
blurb here

")))

; ---------------------------------------------------------------------------

(defn -main

"TOPIC database: entry point of script"

    ([args]
        (cond
            (< (count args) 1) (blurb)
            (and (= (count args) 1) (= (s/lower-case (nth args 0)) "-i"))
            (indices)
            :else (load-block (apply str (interpose " " args))))))

; ---------------------------------------------------------------------------

(-main (rest *command-line-args*))

; eof

-- 
later on,
Mike

http://www.topcat.hypermart.net/index.html
0
Reply mss (26) 2/16/2011 3:29:56 PM


0 Replies
28 Views

(page loaded in 4.205 seconds)

Similiar Articles:

7/20/2012 5:41:39 AM


Reply: