I was planning to have match/match.scm be a common library, then the
implementation-specific part, would eventually end up in a cond-expand
in match.sld, and match.sld would be where the `is-a?`, `slot-ref`,
and `slot-set! would end up (optionally defined for implementations
that do record matching). I have it working on Guile and Gauche and I
did write a test set-up for srfi-99, if I find something to test it
on. I will change the `@` and `$` to say record.
On Mon, Jul 27, 2020 at 10:17 PM Adam Nelson <xxxxxx@nels.onl> wrote:
>
> SRFI 9 defines `define-record-type` and nothing else. It doesn't specify anything about reflection on records. SRFI 99 is an extension to SRFI 9. It defines some procedures to acquire a `rtd` (record type definition) and list the fields of that record type. It can be used to take apart an arbitrary record, without knowing what kind of record it is at compile time.
>
> The definitions of `@` and `$` don't appear to use SRFI 9 or 99, though. Your `match.scm` uses `is-a?`, `slot-ref`, and `slot-set!`; these aren't part of R7RS or any SRFI. They're common operator names in the CLOS-like object systems that most Schemes define. It looks like Chibi defines them to work on records in the obvious way, but this won't work in other Schemes. The sample implementation should probably uses SRFI 99 as a baseline, with special implementations for Schemes that don't support it. Or maybe define `is-a?`, `slot-ref`, and `slot-set!` outside of `match.scm`, and use different definitions for different Schemes.
>
> The document defines `@` and `$` as working on "objects", not records. Since there's no portable concept of "object" in Scheme (except records), it should say "record" instead.
>
> (There should probably be a SRFI for a simple CLOS-like object system, since almost every Scheme has one...)
>
> On 7/27/20 9:20 PM, Felix Thibault wrote:
>
> Thanks! And thanks for the info, I'll be looking over syntax.sld for the next few days. It does look like record matching is the most troublesome feature- (but as far as names goes it already comes with two no-problem synonyms [struct and object]). Could you fill me in on why the record syntax makes this dependent on srfi-99? I thought srfi-9 was the standard record for r7rs so I have been focused more on that.
>>
>> The SRFI 204 sample implementation is coming along nicely! I've written something similar in my Schemepunk library, which defines a Chibi-like match that works in 7 Schemes. You can see the definition of match in syntax.sld, starting at line 296. My implementation is structured a bit differently; it constructs a cond expression, and has a macro for the predicate (match?) and body (match-body) of each clause. It's missing a lot of the more advanced features, but could still be useful for reference. (I think and patterns are broken right now, because of changes I made to chain for SRFI 197.)
>> I noticed that you were starting to implement match for Gerbil Scheme. I've already done that for my implementation, and it was by far the most difficult to implement. The problem is that the underscore is a reserved word in Gerbil, and this cannot be overridden. Gerbil also has inconsistent support for Oleg's symbol-distinguishing macro trick. I combined the solutions to all of these issues into the syntax-symbol-case macro (syntax.sld, line 165), which might be useful to you.
>> Kawa Scheme might also be difficult. I tried running the SRFI 204 sample implementation, and it failed because @ is reserved in Kawa; once I removed the @ clauses, it seemed to work. It might be a good idea to decide on an alternate symbol for record matching.
>> Or is record matching even a necessary feature? Record matching makes this SRFI dependent on SRFI 99, limiting its portability. And some Schemes, like Chicken, only allow reflecting on records if you explicitly import SRFI 99 or set -D debug.
>
>