On Tuesday, June 2, 2015 at 2:00:17 PM UTC-4, piast...@gmail.com wrote:
>
> I don't know how to read this: 
>
>
> http://www.leonardoborges.com/writings/2012/12/02/monads-in-small-bites-part-ii-applicative-functors/
>
> (defmulti pure (fn [f _] f))(defmethod pure List [_ v]    "Wraps value v in a 
> list"    (List. [v]))
>
>
> Is this a List followed by a vector of 2 elements, or this a List object 
> whose constructor is being called with 2 arguments? 
>
> List [_ v]
>
>
> Also, am I correct to say that "_" is used instead of "f" purely to 
> communicate intent to the next human developer who looks at this? It can 
> not be indicating a type or a signature to the JVM, yes? 
>

The (List. [v]) line is calling a class constructor, for some class named 
"List", with a single argument, which is a one-element vector containing 
the second argument to a multimethod whose first argument is being used 
solely to decide dispatch.

The _ is a valid Clojure identifier, but one that is conventionally used to 
name an argument that is being ignored rather than used. So the dispatch 
function is ignoring the second argument and using the first, and the one 
method of the multimethod we see here is ignoring the first argument and 
using the second. You may sometimes see more than one _ in one place, e.g. 
[_ _ _ x y _ z], which technically has each _ produce a binding that 
shadows the preceding _ binding, but again if the convention is being 
followed none of those parameters are actually being used anyway.

-- 
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/d/optout.

Reply via email to