Skip to content

Instantly share code, notes, and snippets.

@pmbauer
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmbauer/d9f25bc3b84a23c2ffe5 to your computer and use it in GitHub Desktop.
Save pmbauer/d9f25bc3b84a23c2ffe5 to your computer and use it in GitHub Desktop.
;; One example of why one might want to generate platform specific feature macros
;; I'm not saying this is a good DSL, just possible with https://github.com/feature-macros/clojurescript/tree/feature-macros/feature-macros-demo
(deftype-unified Foo [bar]
unified/Counted [(count [_] {:cljs (-count bar)
:clj (.count bar)})]
BazProtocol
(fizz [_] :buzz))
;; where unified/Counted [...] expands to clojure.lang.Counted/count on :clj and ICounted/-count on :cljs
;; vs reified instances of #+clj #+cljs *every* *single* *time* we need to paper over implementation differences
(deftype Foo [bar]
#+clj clojure.lang.Counted
#+cljs ICounted
#+clj (count [_] (.count bar))
#+cljs (-count [_] (-count bar))
BazProtocol
(fizz [_] :buzz))
;; IIR, one of Clojure's guiding design principles is to not add features that make future need X impossible
;; Without first-class data representation, feature expressions run counter to that principle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment