On Mar 28, 4:28 pm, David Nolen <dnolen.li...@gmail.com> wrote: > On Sat, Mar 28, 2009 at 4:40 PM, mikel <mev...@mac.com> wrote: > > > So, at minimum, to make a solid port, you need to add a function that > > can return a sensible type value for any input > > Enjoying the thread. Out of curiosity for which Clojure values is the return > value of the type function undefined? Try this: (type (proxy [clojure.lang.IMeta clojure.lang.IRef][])) java.lang.UnsupportedOperationException: meta (NO_SOURCE_FILE:0) [Thrown class clojure.lang.Compiler$CompilerException] No doubt someone is going to point out that the proxy object I created there is useless; that's true, but beside the point. The point is that it's straightforward to create some value v for which (type v) is undefined. In order to make a Clojure-friendly version of CLOS, you need some concept of object type such that you can define a function that returns a sensible type for any value. The way that Dylan handled situations similar to Clojure's proxy objects was with objects called singletons; a singleton is an object that represents a specific value as a class. For example, (singleton 5) returns an object that is a class, but is also the integer 5. You can define methods that specialize on such objects. For example, below is an excerpt from the UI libraries of Apple's long- ago Bauhaus project. Notice the first line: (define-method build-form ((key (singleton label:)) The equivalent syntax in Clojure (if clojure had these mechanisms) would be: (define-method build-form [[key (singleton :label)] (There was no equivalent of defn in Dylan; there was only define- method, because all values were instances of Dylan classes, and in that environment a defn is no different from a define-method without value constraints. Consequently, all functions were polymorphic; all unsealed functions could be extended by adding new method definitions.) (define-method build-form ((key (singleton label:)) remaining-spec form current-x current-y layout-vector) (ignore key) (bind ((label-string (car remaining-spec)) (next (rest remaining-spec))) (add-feature-to-form (make <label-text> string: label-string top: current-y left: current-x style-array: $espy-10-bold-pointer) next form current-x current-y layout-vector))) --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---