guile-user
[Top][All Lists]
Advanced

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

Re: Guix records


From: Taylan Kammer
Subject: Re: Guix records
Date: Wed, 10 Feb 2021 06:37:32 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

On 10.02.2021 02:02, Dr. Arne Babenhauserheide wrote:

Taylan Kammer <taylan.kammer@gmail.com> writes:
The most feature-rich record system supported by Guile is probably the
R6RS record system, which is available through the modules:

   (rnrs records syntactic (6))
   (rnrs records procedural (6))
   (rnrs records inspection (6))
Here's a super brief example usage of R6RS records, demonstrating that
field accessors are defined implicitly, but constructors still use an
unnamed sequence of arguments to assign fields:

   (import (rnrs records syntactic (6)))  ; must use 'import' for R6RS

   (define-record-type (cat make-cat cat?) (fields name age color))

   (define garfield (make-cat "Garfield" 42 'orange))

   (cat-color garfield)  ;=>  orange

I did not know about that shorthand — thank you!

I always did this:

(import (srfi srfi-9)) ; define-record-type
(define-record-type <cat>
   (make-cat name age color)
   cat?
   (name cat-name) (age cat-age) (color cat-color))

Compared to that the syntactic form you showed is much nicer.

I actually prefer the conceptual simplicity and explicit nature of SRFI-9 to be honest, but yeah, it can be very verbose.

Is there a difference in efficiency or such?

Theoretically there shouldn't be, since the implicit defining of the accessors happens at compile time. However, pre Guile 3.0, the R6RS record system was implemented completely independently from the SRFI-9 implementation, so the two could have various differences in performance.

According to the 3.0 release notes, R6RS and SRFI-9 now both use a unified core record system under the hood and should therefore have equivalent performance characteristics I suppose.

Best wishes,
Arne


- Taylan



reply via email to

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