Fork me on GitHub
#clojure
<
2018-07-29
>
seancorfield01:07:56

@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

emccue01:07:35

thats unfortunate, but whatever

emccue01:07:57

kinda stinks that so much of the functionality in clojure is in interfaces and not protocols

seancorfield01:07:01

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

emccue01:07:05

yeah its not really worth it for me to use deftype

emccue01:07:15

ill just stick to a specific function

seancorfield01:07:31

Why do you need to override count for a record? (I'm curious as to the use case)

emccue01:07:54

progress bar

seancorfield01:07:05

I'd be concerned that it would break a bunch of core functions if your count isn't just the underlying count behavior...

emccue01:07:06

10 states on a history, user steps through 5

emccue01:07:27

ill just define a history/length

seancorfield01:07:10

That seems better than overloading a standard, built-in behavior...

emccue01:07:25

I need to add the "I am a bad programmer" disclaimer to my username

emccue01:07:49

ill roll with that

emccue01:07:30

curious what the technical difference is between protocols and interfaces though

emccue01:07:38

like, what is the difference in bytecode that makes it so I can extend any type with a protocol but not with interfaces

tbaldridge02:07:17

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