On Wed, Feb 8, 2012 at 9:46 PM, Simon Holgate <simon.holg...@gmail.com> wrote:
> Could anyone point me to a description of "->" and "->>", please?
>
> I've seen a few references to them (e.g. git://gist.github.com/1761143.git)
> but nothing in "Programming Clojure". Google doesn't seem to like
> searching for such strings.

These macros are collectively called the "threading macros". `->` is
called "thread first" and `->>` is called "thread last". These macros
lets you write deeply nested function invocations in a relatively flat
manner.

Something like

(-> foo
  (bar x)
  (baz y)
  (quux z))

gets re-written as (quux (baz (bar foo x) y) z). So `->` basically
threads the first expression through the subsequent forms, inserting
it as the second item in the list (aka the first arg).

Similarly, something like

(->> foo
  (bar x)
  (baz y)
  (quux z))

gets re-written as (quux z (baz y (bar x foo))).

More docs here - http://clojuredocs.org/clojure_core/clojure.core/-%3E
& http://clojuredocs.org/clojure_core/clojure.core/-%3E%3E

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

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