Hi,

how about this?

(def sentence-spec {1 {:n 2 :fmt "[1] a=%d b=%d"}
                    4 {:n 0 :fmt "[4]"}
                    5 {:n 1 :fmt "[5] z=%d"}})

(defn input-reader
  [inputQ eof?]
  (fn [byteArray]
    (.put inputQ (or byteArray eof?))))

(defn input-bytes
  [inputQ eof?]
  (->> (repeatedly #(.take inputQ))
    (take-while #(not (identical? % eof?)))
    (mapcat identity)))

(defn sentence-seq
  [bytes-seq]
  (lazy-seq
    (when-let [s (seq bytes-seq)]
      (let [{:keys [n fmt]} (sentence-spec (first s))
            [sentence tail] (split-at n (rest s))]
        (cons (apply format fmt sentence)
              (sentence-seq tail))))))

(defn the-app
  []
  (let [eof?   (Object.)
        inputQ (LinkedBlockingQueue.)]
    (init-serial-port (input-reader inputQ eof?))
    (sentence-seq (input-bytes inputQ eof?))))

It uses a guard to detect EOF (assuming a nil "array" means EOF) and turns 
the input queue into a sequence of bytes. Then the translation to sentences 
is based on this input byte sequence.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to