Re: CLJS: extending types like keyword, symbol and string?

2012-11-30 Thread Frank Siebenlist
Sorry - just noticed the "Re: cljs: extend-protocol to Keyword" discussion of a few days ago. Maybe we should start maintaining an FAQ-like wiki-page with summaries of those issues/features… -FS. On Nov 30, 2012, at 5:17 PM, Frank Siebenlist wrote: > When I ask for the type of a keyword, s

CLJS: extending types like keyword, symbol and string?

2012-11-30 Thread Frank Siebenlist
When I ask for the type of a keyword, symbol or string, cljs gives me the same answer: --- ClojureScript:cljs.user> (type "jaja") # ClojureScript:cljs.user> (type 'jaja) # ClojureScript:cljs.user> (type :jaja) # ClojureScript:cljs.user> (= (type :jaja)(type 'jaja)(type "jaja")) true --- but the

Re: extending types

2011-05-19 Thread Ken Wesson
On Fri, May 20, 2011 at 2:54 AM, Ken Wesson wrote: > => (def r (put (DateMap. {}) :foo (java.util.Date.))) > #'user/r > => r > {:foo "Thu May 19 22:44:37 PDT 2011"} > => (get-as-date r :foo) > # Bah, copy and paste error. Test it and you'll find it works regardless. Somehow I got the result from

Re: extending types

2011-05-19 Thread Ken Wesson
On Thu, May 19, 2011 at 11:26 PM, Lachlan wrote: > Just working through this, if we take your example above, what if I > wanted to override the 'put' method rather than define a new one, > since we don't have access to 'proxy-super'.  For example making a map > that enforces storage of dates in a

Re: extending types

2011-05-19 Thread Lachlan
Hi Ken, I hadn't thought of using explicit metadata for this purpose, I guess I was thinking that the class of the object would determine what it could do. Just working through this, if we take your example above, what if I wanted to override the 'put' method rather than define a new one, since w

Re: extending types

2011-05-18 Thread Ken Wesson
On Wed, May 18, 2011 at 7:19 PM, Lachlan wrote: > A further example of this proxy method not working would be trying to > add methods to a clojure.lang.PersistentVector.  It doesn't seem to > have an ?? => (seq (.getConstructors (type []))) nil PersistentVector lacks public constructors. => (f

Re: extending types

2011-05-18 Thread Lachlan
On 19 May 2011 01:55, David Nolen wrote: > On Tue, May 17, 2011 at 5:52 PM, jlk wrote: >> >> (proxy2  [String] >> AProtocol? >> (theseBehaveAsStringsWithThisAdded [] ...) >> >> leaving regular Strings unaffected? > > The problem is that Java is inherently and early-bound design. It's > difficult

Re: extending types

2011-05-18 Thread David Nolen
On Tue, May 17, 2011 at 5:52 PM, jlk wrote: > (proxy2 [String] > AProtocol? > (theseBehaveAsStringsWithThisAdded [] ...) > > leaving regular Strings unaffected? The problem is that Java is inherently and early-bound design. It's difficult to do efficient composition a la Objective-C where you

Re: extending types

2011-05-18 Thread Jonathan Fischer Friberg
My interpretation of the questions was that "String" was only an example. Regardless of what the question actually was, I felt that some clarifying of "proxy" would be appropriate. Jonathan On Wed, May 18, 2011 at 4:52 PM, Ken Wesson wrote: > On Wed, May 18, 2011 at 10:40 AM, Jonathan Fischer F

Re: extending types

2011-05-18 Thread Ken Wesson
On Wed, May 18, 2011 at 10:40 AM, Jonathan Fischer Friberg wrote: > If I'm not mistaken, you should NOT use extend-type to extend java classes > (only interfaces and protocols). > > To answer your questions, you can "extend" a class and interfaces with > proxy, like so: > > (proxy [classA interfac

Re: extending types

2011-05-18 Thread Jonathan Fischer Friberg
If I'm not mistaken, you should NOT use extend-type to extend java classes (only interfaces and protocols). To answer your questions, you can "extend" a class and interfaces with proxy, like so: (proxy [classA interfaceA interfaceB] [] ...) Note that you cannot use protocols directly, you can ho

Re: extending types

2011-05-17 Thread Ken Wesson
On Tue, May 17, 2011 at 5:52 PM, jlk wrote: > Hello > > Apologies if I'm misunderstanding something here, but is it possible > to easily extend to a new java type?  For example: > > proxy -> allows you to implement methods that are already defined in > an interface or class, so you can redefine me

extending types

2011-05-17 Thread jlk
Hello Apologies if I'm misunderstanding something here, but is it possible to easily extend to a new java type? For example: proxy -> allows you to implement methods that are already defined in an interface or class, so you can redefine methods (proxy [ClassA] [] (thisMustBeDefinedInClassA [] .