On 13 Nov 2009, at 08:13, Mark Engelberg wrote:

> Is there a way to customize the way that types defined by deftype
> print in the REPL?

Implement the multimethod clojure.core/print-method for the associated  
type tag:

(deftype Foo ...)

(defmethod clojure.core/print-method ::Foo [x] ...)

> While these datatype and protocol constructs are taking shape, maybe
> now is the time to discuss what kind of "privacy" settings are
> worthwhile in a language like Clojure.  I think Java's system of
> private/public/protected is probably overkill for Clojure.  But do
> people feel that some degree of data hiding is worthwhile?  For
> example, might you want to hide some deftype fields from keyword
> lookup?

Coming from a Python background, I don't think access restrictions are  
necessary. However, flagging fields as "not meant for use by  
outsiders" could be of interest for documentation tools, to make it  
clear what client code can safely rely on.

Note also that you can always make the deftype private (it's a var  
like any other) and restrict all use of it to public functions defined  
in the same namespace. That doesn't exclude defining protocols and  
multimethods on this type elsewhere, because its type tag is a  
namespace-qualified symbol that can be used anywhere.

> Protocols:
>
> I don't understand whether there's any way to provide a partial
> implementation or default implementation of a given
> protocol/interface, and I believe this to be an important issue.

I don't think that partial implementations are possible at the moment,  
but I agree that it would be useful. A default implementation can be  
provided as an implementation of Object. It's not quite the same as a  
default implementation for a multimethod, as it doesn't apply to types  
identified by a metadata type tag, but in practice it can be good  
enough or even better.

> For example, a protocol for < and > that provides a default
> implementation of > in terms of < and a default implementation of < in
> terms of >, so that you only need to implement one and you get the
> other for free.

Right. I have such a case in my test implementation for multiarrays  
(soon to be put on Google Code...), where I'd want to define a default  
implementation for "rank" as "length of the shape vector".

Konrad.

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