This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-29
Channels
- # beginners (18)
- # boot (1)
- # cider (12)
- # clojure (18)
- # clojure-russia (5)
- # clojure-uk (8)
- # clojurescript (17)
- # cursive (7)
- # datomic (10)
- # editors (1)
- # figwheel-main (14)
- # hoplon (2)
- # hyperfiddle (1)
- # keechma (2)
- # leiningen (25)
- # off-topic (5)
- # onyx (3)
- # reagent (53)
- # reitit (6)
- # shadow-cljs (14)
- # spacemacs (3)
- # tools-deps (14)
- # uncomplicate (12)
@emccue Yeah, here's the list of types behind a bare defrecord
:
user=> (defrecord Foo [])
user.Foo
user=> (->> Foo ancestors (map str) sort clojure.pprint/pprint)
("class java.lang.Object"
"interface clojure.lang.Associative"
"interface clojure.lang.Counted"
"interface clojure.lang.IHashEq"
"interface clojure.lang.IKeywordLookup"
"interface clojure.lang.ILookup"
"interface clojure.lang.IMeta"
"interface clojure.lang.IObj"
"interface clojure.lang.IPersistentCollection"
"interface clojure.lang.IPersistentMap"
"interface clojure.lang.IRecord"
"interface clojure.lang.Seqable"
"interface java.io.Serializable"
"interface java.lang.Iterable"
"interface java.util.Map")
nil
kinda stinks that so much of the functionality in clojure is in interfaces and not protocols
For comparison, deftype
provides almost nothing:
user=> (deftype Bar [])
user.Bar
user=> (->> Bar ancestors (map str) sort clojure.pprint/pprint)
("class java.lang.Object" "interface clojure.lang.IType")
nil
Why do you need to override count
for a record? (I'm curious as to the use case)
I'd be concerned that it would break a bunch of core functions if your count
isn't just the underlying count
behavior...
That seems better than overloading a standard, built-in behavior...
like, what is the difference in bytecode that makes it so I can extend any type with a protocol but not with interfaces
Protocols are interfaces, when the type is defined after the protocol. When the protocol is defined after the type, protocols find the function to call by looking up the type in a hashmap, and that result is cached sometimes