Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple-dispatch extended to protocol not effective #750

Open
borkdude opened this issue May 20, 2022 · 1 comment
Open

simple-dispatch extended to protocol not effective #750

borkdude opened this issue May 20, 2022 · 1 comment

Comments

@borkdude
Copy link
Collaborator

borkdude commented May 20, 2022

Repro:

(ns user
  (:require [clojure.pprint :as pprint]))

(defprotocol Schema)
(defrecord ASchema []
  Schema)

(defrecord Foo [x])

(defmethod clojure.pprint/simple-dispatch user.Schema [_] (println "PRETTY"))

(prefer-method clojure.pprint/simple-dispatch user.Schema clojure.lang.IRecord)
(prefer-method clojure.pprint/simple-dispatch user.Schema java.util.Map)
(prefer-method clojure.pprint/simple-dispatch user.Schema clojure.lang.IPersistentMap)

(clojure.pprint/pprint (ASchema.))

This should print "PRETTY".

cc @frenchy64

@frenchy64
Copy link

I'm guessing the most general fix for this is in clojure.core/isa?. Also worth testing print-method.

./bb
Babashka v0.8.3-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (defprotocol P) (defrecord R [] P)
#'user/P
user=> user.R
user=> (isa? user.R user.P)
false
clj
Clojure 1.11.1
user=> (defprotocol P) (defrecord R [] P)

P
user.R
user=> (isa? user.R user.P)
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants