2010/12/8 Surgo <morgon.kan...@gmail.com>

> To help myself learn Clojure, I figured I would write a pattern
> matching / destructing macro to better look like languages I'm more
> familiar with; i.e., destructuring by [first|second|rest] instead of
> [first second & rest]. To do this I'm turning the aforementioned
> vector into a string (via str) and looking for / replacing the |
> character. However, this led to the following issue...
>
> (def test "abc")
> (first test)
> > \a
> (rest test)
> > (\b \c)
> (string? (rest test))
> > false
>
> It would be really helpful if first/rest returned strings (or a
> character in the case of first), not lists, when given string input.
> Is there a design reason for the current behaviour and, if so, are
> there equivalent built-in functions that do the right thing for
> strings?
>

(first "abc") gives you a character.

(rest anything) returns a seq, by definition. It's not about Strings, it's
the contract of rest. A String is not a seq, but it's viewable as a seq, in
which case each element of the seq will be a character of the String.

Note that this is not particular to String, but to almost any clojure
datastructure :

(rest [1 2 3])  doesn't return a vector either, but a seq: (2 3)

etc.

You seem to want to not use seq abstractions, but String manipulation
abstractions, here.

>
> --
> 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<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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