Re: Generic interfaces Daphne Preston-Kendal 23 Jul 2021 18:12 UTC

On 23 Jul 2021, at 19:51, Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:

> Can you explain this to me (a CL-noob)?

(type-of x) gives you a datum, in CL land usually a symbol, that tells you what kind of thing x is. That’s the name of a type, vaguely corresponding to a record-type descriptor in R6RS terms (but applicable to every object in the system, not just user-defined records).

If we had type-of in Scheme-land, we’d likely want to return type descriptors rather than symbols. But R7RS small has no real concept of type descriptors, except whatever the first argument to define-record-type is bound to. We have no type descriptors for lists, numbers, strings, etc. And crucially, there's no portable way in R7RS small, even in the case of record types, to get a record type descriptor from a record type instance. The only way to find out what type something is is to call predicates in turn until you get a #t answer.

This means you can’t portably implement polymorphic dispatch by storing type descriptors in a table (or similar) to avoid having to call every predicate in turn. This is also what I meant with Scheme generic functions being inherently incompatible with the CLOS/JVM/CLR approaches, which all use dispatch based on type descriptors (whatever those look like in the relevant runtimes) rather than predicates.

Daphne