2010/12/22 Ken Wesson <kwess...@gmail.com>

> On Wed, Dec 22, 2010 at 10:59 AM, Benny Tsai <benny.t...@gmail.com> wrote:
> > Hi Marek,
> >> Great! I was wondering whether Clojure supports something like
> >> tuple-unpacking in Python. Does it also support "patterned"
> >> destructuring like:
> >>
> >> first, *middle, last = sequence(...)
> >> -or-
> >> first, rest = sequence(...)
> >>
> >> The latter could be achived by something like `first+rest', I suppose,
> >> but don't know the "Clojure" name for it.
> >
> > The latter is definitely supported; the name after a '&' will be bound
> > to the remainder of a sequence:
> >
> > user=> (let [[fst & rst] [1 2 3]] (println "first:" fst "rest:" rst))
> > first: 1 rest: (2 3)
> >
> > But I don't know of a way to bind the 'middle' elements of a sequence
> > to something.
>
> user=> (let [[x y & more] [1 2 3 4 5]] [x y more])
> [1 2 (3 4 5)]
> user=> (let [[x y z] [1 2 3 4 5]] [x y z])
> [1 2 3]
> user=> (let [[_ _ a b] [1 2 3 4 5]] [a b])
> [3 4]
>
> You can grab any fixed position in this way, as well as a "rest" that
> is the tail of the sequence past the last of such.
>
> By the way, what is "fmap"? It has no entry at
> http://clojure.github.com/clojure/clojure.core-api.html, and
>
> user=> fmap
> #<CompilerException java.lang.Exception: Unable to resolve symbol:
> fmap in this context (NO_SOURCE_FILE:23)>
>
> in my copy of Clojure 1.2.
>

Answer in Benny's first contribution to this thread: *
 (:use [clojure.contrib.generic.functor :only (fmap)]))

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