unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Taylan Kammer <taylan.kammer@gmail.com>
To: Olivier Dion <olivier.dion@polymtl.ca>, guile-user@gnu.org
Subject: Re: Guix records
Date: Wed, 10 Feb 2021 00:14:19 +0100	[thread overview]
Message-ID: <c7f22d7f-8754-27f2-1bff-30172ad06cde@gmail.com> (raw)
In-Reply-To: <87lfc2e9vn.fsf@clara>

On 05.02.2021 17:51, Olivier Dion via General Guile related discussions 
wrote:
> Hello,
> 
> In the module (guix records), there's some very nice syntax rule
> `define-record-type*` that allows very powerfull declarative style of
> records.  For example:
> ----------------------------------------------------------------------
> (employee
>    (age  30)
>    (name "Foo")
>    (profession "Teacher"))
> ----------------------------------------------------------------------
> 
> I would like to use this feature in my software.  However, I don't want
> to have Guix as a dependency only for that.  For now, I've copied the
> content of (guix records) into (my-software records).  But this put
> burden of maitenance into my hands.
> 
> Thus, I'm looking for an alternative, perhaps there's a Guile library
> (other than Guix' module) or a SRFI that offers similar feature?
> 

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))

However, it doesn't allow a definition style like in your example, where 
you explicitly name the fields that you're assigning values to during 
instance creation.

It does, however, implicitly define getters (and setters for mutable 
fields).

The Guile documentation is brief.  You might want to read the R6RS spec 
or search for another guide for detailed explanations and examples of 
how to use the R6RS record system, if it sounds interesting.

Note that it's quite dissimilar to the SRFI-9 system, and some aspects 
of it are rather complex, which is why many people don't like it.  To be 
honest I find some of those complex features quite ingenious on paper, 
though I couldn't say how often they would prove to be useful in practice.

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



Then there is SRFI-99 which could be seen as an update to SRFI-9, but 
last I checked it's not in Guile yet.  It also doesn't really feature 
the declarative style like in your example.



- Taylan



  reply	other threads:[~2021-02-09 23:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 16:51 Guix records Olivier Dion via General Guile related discussions
2021-02-09 23:14 ` Taylan Kammer [this message]
2021-02-10  1:02   ` Dr. Arne Babenhauserheide
2021-02-10  5:37     ` Taylan Kammer
2021-02-10  8:38       ` Dr. Arne Babenhauserheide
2021-02-09 23:32 ` Aleix Conchillo Flaqué
2021-02-10  0:28   ` Olivier Dion via General Guile related discussions
2021-02-10 21:11     ` Aleix Conchillo Flaqué
2021-02-26 17:36 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7f22d7f-8754-27f2-1bff-30172ad06cde@gmail.com \
    --to=taylan.kammer@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=olivier.dion@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).