Skip to content

Why not definterface, and why+how is deftype limited? #1013

Description

@edenworky

The README mentions that definterface is not supported and that deftype has limited support with no further elaboration. The Babashka book details this a bit further https://book.babashka.org/#differences-with-clojure but is somewhat inconsistent with the README, saying there's "no deftype" at all. I take it this means sci has a limited deftype while Babashka doesn't have one at all?

definterface, being a Java-specific thing, makes sense insofar as not being implemented natively in sci, but is there any good reason not to be able to pass in definterface in SCI-on-JVM? Is this possible already, and thereby we'd be able to run Java-specific Clojure code on SCI-on-JVM by binding definterface to the session? If so that's great, and should likely be documented somewhere (I can see why enabling it by default on the JVM would be weird/undesired, although it would simplify the existing code, such as here https://github.com/babashka/sci/blob/master/src/sci/impl/records.cljc#L19 which errors out given an interface only on the JVM, which is the one place we have definterface anyway).

deftype to my understanding is mostly complicated because it fully relies on JVM constructs for its machinations, and there isn't really any way even in clojure.core to take a value and get a set of everything it satisfies?, which explains the one limitation (listed, again, in the Babashka book and not in the sci docs anywhere) is that reify only supports one type? Is this the case for sci in general? Is this the "limited support" described by the README? Are there other ways it's "limited?"

In a broader sense, is full/better deftype and/or definterface support planned? I can think of a few ways involving meta-in-reify and/or a macro generating a composition of deftypes to potentially address this, but the immediate issue is that the current state of these things is not apparent in the docs anywhere. If I understand it I'd be glad to send a PR for the README.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions