Uploaded image for project: 'ClojureScript'
  1. CLJS-414

Implement specify, allowing instances to implement protocols

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: None
    • Labels:
      None

      Description

      Javascript objects are fully dynamic. Currently, ClojureScript has no mechanism to exploit that for protocol implementation.

      CLJS-398 Closed was a first attempt to implement an operation to extend single instances, but it fell short because it offered no control over which closures to attach onto the object (i.e. allocates every time). Also, specify is a much better name than extend-instance.

      extend-type can be implemented in terms of specify (by specifying the .prototype), but extend-type has grown from its humble beginnings
      https://github.com/clojure/clojurescript/blob/b75730da8abc3abc6134d8dd9ec426ab792d3662/src/clj/cljs/core.clj#L42
      to an monster of complexity
      https://github.com/clojure/clojurescript/blob/72e55315c6973caa74af39b66052424f73872033/src/clj/cljs/core.clj#L438
      Currently it does

      • print warnings
      • optimize IFn impls
      • special case the Object "protocol"
      • special case js builtins

      and all that in a single macro body. So this is also a good opportunity to do some refactoring.

      specify should have an interface similar to extend-type. Additionally a lower level operation is needed to attach existing lambdas as protocol methods. It's called specify* in my current implementation. It takes a lambda for every specified protocol-method-arity, with a syntax loosely based on clojure.core/extend.

        Attachments

          Activity

            People

            • Assignee:
              bendlas Herwig Hochleitner
              Reporter:
              bendlas Herwig Hochleitner
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: