You could probably make it work in cljs by: 1. Putting IMultiMethod back to cljs version, except using is-a?, not core/isa? 2. Rewrite the Is-A protocol code to use the cljs rules: - Remove any code about class hierarchies - Only extend Is-A on actual types, so cljs.core.Vector, not IPersistentVector, cljs.core.ObjMap, not IPersistentMap Of course, I have maybe 2 days total of cljs experience, so an expert can jump on this thread any time :) .
Re: #2 above, is what I'm doing in my JVM clojure code (extending on IPersistentVector, etc.) considered bad form? I ask because: - from http://clojure.org/protocols : "You can implement a protocol on an interface... opens the door to incidental multiple inheritance of implementation... which [interface] is used is unspecified." When I read that, I thought "Oh, lord. I'm going to have a horrible C++ nightmare tonight." - But I've seen extension on interfaces in basically all of the JVM clojure.core.* code. Are they using some undocumented convention so that the above problem won't happen? Also, does someone know of a good example of testing code that modifies global state? Right now I'm adding multimethods and derive-ing things, extending protocols, etc.. I'd like to make sure tests don't interfere with each other. This might all be off topic. Should I start a new thread (or two)? --Leif On Saturday, July 14, 2012 4:44:37 AM UTC-4, Dave Sann wrote: > > Can this be used in clojurescript? > > It looks like yes > > But, taking the given clj example, my first question is how can I extend a > protocol to the equivalent of IPersistentMap. Given that maps in > clojurescript are protocols, this seems harder. > > D > > > On Wednesday, 11 July 2012 16:52:47 UTC+10, Leif wrote: >> >> Thanks! >> >> The similarity is no accident: When you consider it, 'isa?' is a >> generalized subtyping relation: >> >> (isa? Double Number) ==> Double <: Number >> (isa? ::goat ::animal) ==> ::goat <: ::animal >> (isa? 1 x) ==> #{1} <: x, which makes sense if you define the value x to >> mean "the set of all things equivalent to x" >> >> Specifically for the keyword case, clojure.core lets you define ad hoc >> hierarchies, which you could view as type lattices. This project lets you >> define ad hoc type lattice relations. >> >> You might be interested in the papers on LIFE. They define "sorts" for >> logic terms (very much like types), and an algorithm for unifying two terms >> (which can be quite a bit more complicated than Prolog terms). >> >> On Wednesday, July 11, 2012 2:22:51 AM UTC-4, Ambrose Bonnaire-Sergeant >> wrote: >>> >>> This is cool :) >>> >>> It reminds me of subtyping between maps in Typed Clojure, where >>> >>> {:a 1, :b 2} <: {:a Number} >>> >>> Thanks, >>> Ambrose >>> >>> On Wed, Jul 11, 2012 at 2:16 PM, Leif <leif.poor...@gmail.com> wrote: >>> >>>> Hi, everybody. I reimplemented the function isa? in terms of a >>>> protocol Is-A. >>>> >>>> The reason why you would want to do that is in the README at >>>> https://github.com/leifp/clj-isa-protocol >>>> >>>> tl;dr: One of the reasons why people are excited about predicate >>>> dispatch is the irritation caused by the dispatch function of a >>>> multimethod >>>> being closed. You have to decide up front what information the dispatch >>>> fn >>>> is going to pull out of your arguments. Changing it afterward is a pain. >>>> >>>> Since the dispatch uses 'isa?' internally, if that function is >>>> extensible, then multimethod dispatch becomes, to a certain extent, open. >>>> See the README. >>>> >>>> Comments, critique, code, and questions welcome. >>>> >>>> Cheers, >>>> Leif >>>> >>>> P.S. As an aside to people that like weird, obscure programming >>>> languages, the rough idea of how is-a? should work for maps was inspired >>>> by >>>> (but very much simpler than) the functional logic language LIFE [ >>>> http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.90.3175 ] >>>> >>>> -- >>>> 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 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