On July 15, 2013 at 6:30:28 PM, Daniel Dinnyes (dinny...@gmail.com) wrote:
Hmm, good point, especially the `let` one... What is `as->`? I can't find 
anything about that.
http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/as-%3E

There is one benefit over `let` though: it is more explicit. Let allows you to 
define independent bindings mixed together with multiple threads of dependent 
bindings (which can be mixed in random combinations). As the number of bindings 
increase it becomes quite messy, and hard to decipher which line depends on 
which. I have seen, even written myself (shame on me), such code. I feel that 
this is the main reason for the `core` threading macros too ("why not use let 
instead?" would still apply then). On the other hand as my simple example code 
demonstrates (off the top of my hat, cuz ya need to show da code!), in a 
functional language the parameter order shouldn't matter, and there shouldn't 
be privileged (main!?) parameter positions (Clojure is the landguage of 
multimethods after all!)
Your ->>> is a bit awkward because the symbol to the left represents the value 
of the previous expression, not the value of the following expression as is the 
case with most "bindings forms" in Clojure. Also, as-> simplifies your use case 
by only needing to identify one name that is used in all the threaded forms. 
Honestly, if I'm going to do anything more complicated that as->, I would 
rethink how I want to express my code.

Anyway, I see the reason for -> and ->> macros and indeed the first and last 
positions are special in some sense. The -> is good for navigating protocols, 
and ->> is good for functions expected/designed to be partially applied. Is 
that correct?
The threading macros operate on the forms directly, so I'm not sure what you 
mean by "partially applied" here. The big win for ->> is that the sequence 
functions in Clojure core expect the sequence to be last. This is handy for 
threading a sequence through multiple transformations.

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to