2009/12/7 Hugo Duncan <hugodun...@users.sourceforge.net>

> On Mon, 07 Dec 2009 06:53:38 -0500, Rich Hickey <richhic...@gmail.com>
> wrote:
>
> > Yes, methods are not really functions. Thinking about them as closures
> > over the object is a good way to go - you can see that analogy in play
> > when you consider recur, which works with these methods, but could not
> > rebind 'this'. The recur case sealed the deal in the decision not to
> > include 'this' in the argument lists.
>
> I had a quick play with protocols, and the biggest problem I had getting
> started was realising that the signature of a method definition in
> defprotocol was different to the signature required to implement the same
> method in deftype.  FWIW, I found it very non-intuitive.
>
>
Hello,

And now that you've got it, do you still feel this  non-intuitive.
Because I had the same feeling first: I thought I would never rembember how
things work and why put 'this-like args there, and not there ...
But now that everything "clicked in place", I feel the last status of what
Rich achieved to do the most natural and intuitive.

Basically, what helped me was along the lines of what Konrad said :
 * defprotocol and extend are "purely functional" : so you have to specify
every argument, including the object the functions acts upon.
 * deftype with embedded protocol definition for the type, or reify, in the
contrary, do not define pure functions. They define methods. You cannot get
them as values and pass them around like higher-order functions, for
example. And you must know this fact, it cannot be an implementation detail.
So, since you know this fact, you remember that you're in a method
definition (in the general sense of object oriented languages : method of a
class) and, as you do with e.g. java, C#, ... , when definining methods, you
do not add the target of the method as an implicit argument.

The big advantage I see to this is that once you get it, you don't have
anymore to remember where 'this is explicit and where it's implicit: it's
intuitive.
The other big advantage is that the use of recur inside these
functions/methods bodies continue to match exactly the signature of the
function/method (otherwise you would have had to remember that, e.g. in
methods defined via deftype, you must place an explicit "this" argument in
the method arg list, but not place it in the recur calls ... :-( )

HTH,

-- 
laurent

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