Everybody, thanks for all your responses.  conj to vector feels good
so that's what I'm playing with now.  Michael, in answer to your
question, and this may be more detail than you bargained for, I'm
playing around with a little state machine parser.  It actually
doesn't do much now, but baby steps as I learn clojure.  Eventually, I
want it to make distinctions between numbers that pass through and
numbers that are transformed.  Am not crazy about having to add a
space at the end of the original string and welcome edifying comments.

(ns test-test.parse
  (:use [clojure.contrib.string :only (split)]))

(defn parse-char [m c]
  (condp = (:state m)
      :degree (cond
               (Character/isDigit c) (assoc m :degree (+ (* (:degree
m) 10) (Character/digit c 10)))
               (Character/isWhitespace c) (assoc
m :state :whitespace :buf (conj (:buf m) (:degree m) " ") :degree 0))
      :whitespace (cond
                   (Character/isDigit c) (assoc
m :state :degree :degree (+ (* (:degree m) 10) (Character/digit c
10)))
                   (Character/isWhitespace c) m)))

(defn parse [s]
  (let [m (reduce parse-char {:state :degree :degree 0 :buf []} (str s
" "))]
    (apply str (:buf m))))

(println (parse "1 2   33"))


On Sep 30, 12:15 am, Michael Gardner <gardne...@gmail.com> wrote:
> On Sep 29, 2010, at 11:01 PM, HiHeelHottie wrote:
>
> > What if you are appending over different lines of code?
>
> Could you give an example of what you're trying to do? Mutable strings are 
> almost never necessary, in my experience.

-- 
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