-> and ->> are for some reason really hard to grasp for many when starting out - me included.
On Mon, Mar 11, 2013 at 11:58 AM, <edw...@kenworthy.info> wrote: > So I understand that: > > (-> foo bar wibble) > > is equivalent to > > (wibble (bar (foo))) > Correct, but that misses the point. Thinking about -> in terms of what the expansion is is not going to work. Think about it like this: (imperative - I know, but explains it better I think) We are going to execute (-> foo bar wibble). We have a variable 'current-value', then: 1. Set current-value to foo 2. Set current-value to (bar current-value) 3. Set current-value to (wibble current-value) 4. Return current-value Another example: (-> {} (assoc :hello 3) (assoc :world 4) (dissoc :world) :hello inc) We get: 1. Set current-value to {} 2. Set current-value to (assoc current-value :hello 3) i.e. {:hello 3} 3. Set current-value to (assoc current-value :world 4) i.e. {:hello 3 :world 4} 4. Set current-value to (dissoc current-value :world) i.e. {:hello 3} 5. Set current-value to (:hello current-value) i.e. 3 6. Set current-value to (inc current-value) i.e. 4 7. Return current-value Result: 4 -> is not implemented imperatively like that, but the point is that you shouldn't think about it in terms of expansion. You should think of it as "we take the initial value, run the first function on the initial value and "store" the result, apply the second function on the stored value and "store" the result, ..." Hope this clear things up. Jonathan -- -- 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.