On Thu, Dec 22, 2011 at 11:59 PM, nchurch <nchubr...@gmail.com> wrote:
> What I really want you to notice is how we are faced with a choice:
> either we improve the library code (presumably by making split
> optionally return an array of separators matched by the regex for
> later reassembly by join, perhaps in metadata of some sort), or we go
> with a less felicitous abstraction.  There probably should be some
> sort of formal analogue to this decision point in the natural language
> text.

Seems to me that the structure is this:

A string that's written language is some alternating form like

word separator word separator ...

where a "word" consists of consecutive alphanumeric characters and a
"separator" consists of consecutive nonalphanumeric characters. The
separators in this paragraph include " ", " \"", "\" ", ". ", and " \"
\", \" \\\"\", \"\\\" \", \". \", ", as well as one more that I can't
add here without generating one more still.

One tends sometimes to want to split a string in such a fashion,
transform the words only, and then reassemble.

This in turn suggests tools like:

(wordify string) -> a seq of strings starting with a separator and
alternating words and separators. The initial separator may be "".
Something like (map #(apply str %) (group-by alphanumeric? string))
with alphanumeric? testing a character, but if the first character of
the first string in the output seq is alphanumeric, a (cons "" %)
needs to be done on the output before returning it.

(map-words* f wordified-string) -> (interleave (take-nth 2
wordified-string) (map f (take-nth 2 (next wordified-string))))

(map-words f string) -> (apply str (map-words* f (wordify string)))

or similar.

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