Stuart,
This is a significant improvement over the original str-utils library,
and goes a long way towards making "string processing kick ass in
Clojure".  I like the fact that you made some design decisions for the
library, and did everything you could to stick with them.  That makes
the library more predictable.

There are two things I would like to discuss about your library.

First, I would change the names of functions functions that collide
with core to str-take, str-drop, etc.  It's just as much to type, and
it is safe to use these names.  Also, it would make it easier for Rich
to promote the library to the standard lib when it's done.

I suspect I am in the minority with my next concern.  The library
takes the string as the first argument, so that it works well with the
-> macro.  When I originally wrote my string library, I favored this
type of signature too.

However, over time I found this signature did not work well with my
code.  Often I would write something like this

(map (comp (partial map (comp   #(str2/drop % 2)
                                #(str2/take % 5)))
                #(str2/split % #"\t"))
        (split a-string #"[\n\r]"))

This felt a little forced, and the methods don't compose very well.
As such, I re-wrote my lib with the string call at the end of the
function.  The main reason was I felt that this approach works better
with the partial function.  The code above becomes like this.

;Granted, this is still a bit ugly.
;I have some other tricks to clean it up.
;That's for another day.
(map (comp (partial map (comp   (partial str2/drop 2)
                                (partial str2/take 5)))
                        (partial str2/split #"\t"))
        (split #"[\r\n]" a-string))

Despite these concerns, I'm still excited about the direction you are
headed with this lib.  Let me know what you think about these points.

Sean Devlin

On Aug 19, 12:45 pm, Stuart Sierra <the.stuart.sie...@gmail.com>
wrote:
> Hey folks,
>
> clojure.contrib.str-utils is one of the first libs I wrote, and it's
> showing its age.  I decided to try to start fresh, incorporating some
> ideas discussed on the list.  In general, I'm trying to provide an
> efficient, functional API for string manipulation.
>
> My new attempt is creatively named clojure.contrib.str-utils2.
>
> One big change: you can't (use ...) it.  That's because it reuses some
> of the names in clojure.core.  For example, it defines "take" and
> "drop" specifically for strings.
> You have to (require '[clojure.contrib.str-utils :as s]) then call
> functions like s/take, s/drop.  If everybody hates this, I'll change
> it, but it would require adding prefixes on a bunch of functions.
>
> Many of these functions are much faster than the equivalent using
> sequences.  For example, str-utils2/escape is 5-10 times faster than
> (apply str (map f "foo"))
>
> Eventually, I'd like to replace the old clojure.contrib.str-utils.
> Let me know what you think.
>
> -Stuart Sierra
--~--~---------~--~----~------------~-------~--~----~
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