On 24 Sep 2024, at 05:14, Antero Mejr - mail at antr.me (via srfi-discuss list) <xxxxxx@srfi.schemers.org> wrote:
> It is possible to implement define-record-type in terms of anonymous
> records. Features like record constructors with default values and
> type-checking are also relatively easy to implement and portable.
>
> Would there be any interest in an anonymous records SRFI?
[chair hat on]
While this would be a potential implementation strategy for define-record-type on R7RS small systems, for R7RS Large it is likely we will adopt some cleaned-up variant of the R6RS record system, which includes support for record types with opacity, sealedness, and nongenerativity, and it is not immediately apparent to me that these features are compatible with this view of records. In any case, to be accepted into the fascicle on records would require support from at least 3 notable Scheme implementations by around this time next year.
That said, even if not adopted into R7RS – or even if ‘records’ of this type build a completely different system from that supported by the R7RS record system* – this idea is intriguing.
[chair hat off]
Some questions:
• How is this distinct from a symbol-keyed hash table or mapping (SRFI 146)?
• SML is statically typed (although I don’t know how well it does at structural typing like e.g. Elm, so this might be a moot point). With static types ‘anonymous’ records can still be optimized to be as efficient as ‘normal’ struct accesses (which in Scheme with R6RS or SRFI 9 d-r-t are just a type check and an array reference, and the type check can be eliminated by a good implementation). Without it, things are trickier.
But not hopeless: JavaScript implementations have the notion of ‘object shapes’ which are used to optimize its idea of records, which also aren’t statically typed. I think doing this optimization ‘right’ in Scheme would require access to the optimizer’s type inferrer, although I’m not 100% certain …
A non-optimized implementation is of course definitely possible in portable Scheme.
Daphne
(* Since no record system offers all the features everyone wants, and trying add all possible features to the built-in record system is clearly against the spirit of Scheme, I actively encourage experiments and libraries and such which provide disjoint (or non-disjoint) type definition systems which provide whichever features you want.)