[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: better error messages through assertions

From: Philip McGrath
Subject: Re: better error messages through assertions
Date: Fri, 1 Apr 2022 15:47:18 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0


On 3/30/22 05:37, Ludovic Courtès wrote:

What is the preferred mechanism for exceptions?

For Guix code, SRFI-34/35.

Likewise, what record system should I use?


(Perhaps we should put answers to these questions in the “Coding Style”
section of the manual.)

As I've looked more closely, I think I'd be porting a fair amount of code that looks like this:

(define-struct (blame-no-swap blame) ()
  #:property prop:equal+hash
  (list blame=? blame-hash blame-secondary-hash))

That code creates a new opaque struct type `blame-no-swap` with parent type `blame` and customizes the behavior of `equal?` and `equal?`-based hashing (but the customization only applies when the two potentially-equal values are both immediate instances of `blame-no-swap`, not a supertype or subtype).

It looks like SRFI 9 doesn't have a notion of opaque or parent types, so it seems like it would be easier to use R6RS records as the basis for porting.

(I think it should still work to use SRFI 9 records for the interface. But I know the representation of blame, among other details, has gotten a lot of attention over the years, so it seems like it would be good to keep the port as close as reasonably possible to the Racket implementation.)

I'm less sure about `equal?` and hashing. I see in [1] that `equal?` can be controlled via GOOPS, and I have the impression that there's some kind of bridging between basic types and GOOPS, but I'm not clear on the details. I don't see anything explicitly about customizing `hash`[2], but maybe that would work the same way?


[1]: [2]:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]