Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
retagged by

Up through Clojurescript 1.10.844, I could reliably tell whether a symbol sym (at macro-expansion time) referred to a protocol by examining the following:

(:protocol-symbol (cljs.analyzer.api/resolve &env sym))

As of the commit for CLJS-3276, this no longer works in my code. As far as I can tell, defprotocol still attaches this data, and cljs.core still uses this method internally. Is there a better / supported way to detect whether a symbol refers to a protocol? I'm very much hoping that this behavior is reintroduced, or else that there is some other reliable method.

1 Answer

0 votes
by

I’m curious why you need to ask this question?

by
The use case is to throw a compile-time error if a particular tool we wrote is being misused (basically, "You can only register protocols!").

The API for the tool is very similar to that of transit's declarative structures for serialization and deserialization handlers, except that it's built to protocols instead of raw types/records.

Because protocols are not reified in CLJS, and `satisfies?` is a macro that will happily and silently answer nonsense questions with `false` when given a non-protocol, a sensible compile-time error to guard against programmer mistakes has been very useful.

Apologies if you meant something else by the question.
by
edited by
If you mean, why is it even a question, I guess it's because it is unclear to me whether `:protocol-symbol` was an implementation detail or part of the supported API. If the former, I'm wondering if there's another mechanism that is supported as part of the analyzer API.
...