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

0 votes
in core.logic by
*Summary:* There is a pattern of {{(definterface IFoo)}} and subsequent uses of {{IFoo}} as a type marker for efficient {{(instance? IFoo x)}} checks. This pattern is not platform agnostic and could potentially block improving support for core.logic on CLJS (which does not support {{definterface}} according to [http://dev.clojure.org/jira/browse/CLJS-1190]).

*Background:*
I was investigating the possibility of using reader conditionals to port parts of core.logic to CLJS (specifically: core.logic.fd) and noticed the usage of interfaces as type markers.

The problem with this is that there is no {{definterface}} in CLJS (to my knowledge; attempting to run {{(definterface IFoo)}} fails in a CLJS repl but works in a CLJ repl).

I have started trying to look for a platform-agnostic replacement for the marker interface pattern but wanted to know if there were specific reasons that this pattern was used before diving into actual coding. I also wanted to know if there were already plans to replace this pattern.

*Remediation:*
Ideally a cross-platform method for achieving this could be implemented. If not, then an alternative method could be defined for and used by CLJS at the cost of some performance.

A possible change would be to replace the marker interfaces with marker protocols, and the instances of {{instance?}} with instances of {{satisfies?}}.

The following seem to be equivalent in Clojure:

{{; interfaces}}
{{(definterface IFoo)}}
{{(definterface IBar)}}

{{(deftype T [] IFoo)}}
{{(instance? IFoo (T.)) ; true}}
{{(instance? IBar (T.)) ; false}}

{{; protocols}}
{{(defprotocol IFoo)}}
{{(defprotocol IBar)}}

{{(deftype T [] IFoo)}}
{{(satisfies? IFoo (T.)) ; true}}
{{(satisfies? IBar (T.)) ; false}}

However, the protocol version also works in ClojureScript.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/LOGIC-170 (reported by alex+import)
...