Thanks for the response.  What if you are appending over different
lines of code?  Would it be slightly more efficient to use one
StringBuilder or not worth the bother.

On Sep 29, 11:32 pm, Stuart Campbell <[email protected]> wrote:
> On 30 September 2010 12:48, HiHeelHottie <[email protected]> wrote:
>
>
>
> > Is there an idiomatic way to build up a string over different lines of
> > code?  Or, should one simply use StringBuilder.
>
> I would just use (str) - it uses a StringBuilder when given more than one
> argument:
>
> user> (source str)
> (defn str
>   "With no args, returns the empty string. With one arg x, returns
>   x.toString().  (str nil) returns the empty string. With more than
>   one arg, returns the concatenation of the str values of the args."
>   {:tag String
>    :added "1.0"}
>   ([] "")
>   ([^Object x]
>    (if (nil? x) "" (. x (toString))))
>   ([x & ys]
>      ((fn [^StringBuilder sb more]
>           (if more
>             (recur (. sb  (append (str (first more)))) (next more))
>             (str sb)))
>       (new StringBuilder ^String (str x)) ys)))
>
> Regards,
> Stuart

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

Reply via email to