This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-14
Channels
- # announcements (7)
- # babashka (13)
- # beginners (98)
- # biff (20)
- # calva (3)
- # clj-kondo (5)
- # clj-otel (6)
- # cljs-dev (96)
- # clojure (22)
- # clojure-austin (29)
- # clojure-conj (4)
- # clojure-europe (53)
- # clojure-nl (2)
- # clojure-norway (63)
- # clojure-uk (3)
- # clojurescript (18)
- # cursive (10)
- # data-science (11)
- # datalevin (2)
- # datomic (7)
- # deps-new (1)
- # fulcro (3)
- # graphql (1)
- # gratitude (4)
- # hyperfiddle (43)
- # kaocha (4)
- # malli (15)
- # pathom (6)
- # polylith (2)
- # reagent (3)
- # reitit (2)
- # releases (6)
- # remote-jobs (1)
- # rewrite-clj (45)
- # ring (4)
- # shadow-cljs (47)
- # sql (5)
- # xtdb (8)
Is it considered undefined behavior to use extend-type
to “override” a record’s implementation of a protocol method? Concretely
(defprotocol Foobar
(foo [this])
(bar [this]))
(defrecord Thing []
Foobar
(foo [this] "Called foo")
(bar [this] "Called bar"))
(bar (->Thing)) ;=> "Called bar"
(extend-type Thing
Foobar
(bar [this] "Overloaded!"))
(bar (->Thing)) ;=> "Overloaded!"
(foo (->Thing)) ;=> "Called foo"
This is behaving how I want it to behave, but is it undefined behavior or a bad practice?I just tried it in JVM Clojure and using extend-type
this way indeed is an error, since under the hood the JVM disallows method implementations to be swapped in and out of classes
That makes me want to believe this is UB, which is unfortunate because there’s a record implementing a protocol in a library and I want to override one method it implements
I would say that patching one fn in a protocol is not really well-defined, it probably won’t change but if this is critical code maybe I wouldn’t rely on it
it seems unfortunate that the ^:export
metadata only takes a boolean. I'd like to have conventional Lisp names in my CLJC code, but export them as (a) camelCase and (b) changing things like *
and ?
to Java-style prefixes like is
.
(defn ^{:export 'isSameThing} same-thing? [args] ...)
I suppose that simply isn't supported. unless maybe shadow-cljs has magic for it?
oh so it does work, but it's not well documented.
cool, thanks!
so yes and no. ^:export
controls the
export name. but in a shadow-cljs :npm-module
the exports: {...}
object uses the this_function
snake case names.
@U05224H0W is that a change you're open to making? we don't need this urgently, but we're at the start of a big effort of porting JS business logic to CLJC.