Skip to content

Commit 53a8949

Browse files
authored
Provide names for methods generated via extend-type and extend-procol (#804)
Fixes #803
1 parent 0e8331f commit 53a8949

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* No longer warn on unused bindings when their name begins with `_` (#756)
2121
* Improve the Python generation for `do`, `if`, `let*`, and `letfn*` forms to avoid unnecessary extra assignments (#793, #794, #799)
2222
* Generate Python classes for `deftype*` and `reify*` forms using modern `@attr.define`, `@attr.frozen`, and `@attr.field` APIs (#799)
23+
* Generate Protocol functions with nicer names based on the protocol function and dispatch type (#803)
2324

2425
### Fixed
2526
* Fix issue with `(count nil)` throwing an exception (#759)

src/basilisp/core.lpy

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6153,12 +6153,12 @@
61536153
(let [impl-method-arities (get impl-method-arity-map proto-method-name)]
61546154
(when (not= impl-method-arities proto-method-arities)
61556155
(throw (ex-info "target-type must implement all protocol method arities"
6156-
{:proto-method proto-method-name
6156+
{:proto-method proto-method-name
61576157
:proto-method-arities proto-method-arity-map
6158-
:impl-method-arities impl-method-arity-map
6159-
:missing-arities (->> proto-method-arities
6160-
(remove impl-method-arities)
6161-
(set))}))))))
6158+
:impl-method-arities impl-method-arity-map
6159+
:missing-arities (->> proto-method-arities
6160+
(remove impl-method-arities)
6161+
(set))}))))))
61626162
(doseq [method-def method-map
61636163
:let [[method-name fn] method-def]]
61646164
(let [dispatch-method (get proto-methods method-name)]
@@ -6196,12 +6196,18 @@
61966196
"Convert a vector of method definitions (as expected by ``extend-protocol`` and
61976197
``extend-type``\\) into a map of method definitions which can be passed to
61986198
``extend``\\."
6199-
[methods]
6199+
[target-type methods]
62006200
(->> (group-by first methods)
62016201
(reduce (fn [m [method-name arities]]
6202-
(->> (map rest arities)
6203-
(apply list `fn)
6204-
(assoc! m (keyword (name method-name)))))
6202+
(let [genned-method-name (symbol
6203+
(str (name method-name)
6204+
"-"
6205+
(if (nil? target-type)
6206+
"nil"
6207+
(name target-type))))]
6208+
(->> (map rest arities)
6209+
(apply list `fn genned-method-name)
6210+
(assoc! m (keyword (name method-name))))))
62056211
(transient {}))
62066212
(persistent!)))
62076213

@@ -6246,7 +6252,7 @@
62466252
`(do ~@(map (fn [[target-type methods]]
62476253
`(extend ~target-type
62486254
~proto
6249-
~(extend-map methods)))
6255+
~(extend-map target-type methods)))
62506256
(sym-and-method-groups specs))))
62516257

62526258
(defmacro extend-type
@@ -6281,7 +6287,7 @@
62816287
[target-type & specs]
62826288
`(extend ~target-type
62836289
~@(mapcat (fn [[proto methods]]
6284-
[proto (extend-map methods)])
6290+
[proto (extend-map target-type methods)])
62856291
(sym-and-method-groups specs))))
62866292

62876293
(defn extenders

0 commit comments

Comments
 (0)