Some examples...

; using ->
(f1 (f2 (f3 (f4 x))))
; can be "flattened" to
(-> x f4 f3 f2 f1)

Useful for nested maps...

user=> (def m {:one {:a 1 :b 2 :c {:x 10 :y 11}}} )
#'user/m
user=> (-> m :one :c :x)
10
user=> (-> x :one :b)
2

On Sun, Feb 1, 2009 at 5:31 AM, Jason Wolfe <jawo...@berkeley.edu> wrote:
>
> On Jan 31, 7:09 pm, wubbie <sunj...@gmail.com> wrote:
>> Hi,
>>
>> I saw in ants.clj a notation (->).
>> what is it?
>> For example,
>> (defn place [[x y]]
>>   (-> world (nth x) (nth y)))
>
> Did you check the docs?
>
> On the website:
> http://clojure.org/API#toc21
>
> Within clojure itself:
>
> user> (doc ->)
> -------------------------
> clojure.core/->
> ([x form] [x form & more])
> Macro
>  Threads the expr through the forms. Inserts x as the
>  second item in the first form, making a list of it if it is not a
>  list already. If there are more forms, inserts the first form as the
>  second item in second form, etc.
>
> Also:
> user> (macroexpand '(-> world (nth x) (nth y)))
> (nth (clojure.core/-> world (nth x)) y)
>
> >
>

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