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

Extending protocols #582

Closed
thomascothran opened this issue Nov 27, 2024 · 1 comment
Closed

Extending protocols #582

thomascothran opened this issue Nov 27, 2024 · 1 comment

Comments

@thomascothran
Copy link

version

0.8.124

problem

I would like to extend protocols to JavaScript Objects, Arrays, etc.

However, I receive an extend_protocol is not defined error each time.

First I define a protocol:

(defprotocol Identity (i [this]))

Then I try to extend it. I tried a few things:

(extend-protocol Identity object (i [s] s))
(extend-protocol Identity js/Object (i [s] s))
(extend-protocol Identity Object (i [s] s))

Similar experiments with array and string produced the same error.

repro

Repro in the squint playground

expected behavior

I'd expect something like this:

(defprotocol Identity (i [this]))
(extend-protocol Identity object (i [s] s))
(i {:hello :world})
; => {:hello :world}
@borkdude
Copy link
Member

This is due to the absence of extend-protocol currently, but not that extend-type is available:

$ ./node_cli.js -e '(defprotocol Identity (i [this])) (extend-type object Identity (i [s] s)) (js/console.log (i 1))'
1

I'll add extend-protocol

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