--- Begin Message ---
Subject: |
[PATCH 0/5] Doing 'match-record' work at expansion time |
Date: |
Sat, 19 Nov 2022 23:23:26 +0100 |
Hello Guix!
This addresses a longstanding issue: making ‘match-record’ efficient,
and allowing it to error out on unknown field names are macro-expansion
time.
It does so by changing the record type identifier passed to
‘define-record-type*’ to a macro that can either expand to the actual
record type descriptor (RTD) or provide the list of fields of
this type:
--8<---------------cut here---------------start------------->8---
scheme@(guix records)> (define-record-type* <foo> foo make-foo foo? (one
foo-one) (two foo-two))
scheme@(guix records)> <foo>
$89 = #<record-type <foo>>
scheme@(guix records)> ,expand <foo>
$90 = #{% <foo> rtd}#
scheme@(guix records)> ,expand (<foo> map-fields f)
$91 = (f (one two))
scheme@(guix records)> ,optimize (match-record x <foo>
(two one)
(list one two))
$92 = (if (eq? (struct-vtable x) #{% <foo> rtd}#)
(let* ((two (struct-ref x 1)) (one (struct-ref x 0)))
(list one two))
(throw 'wrong-type-arg x))
scheme@(guix records)> ,expand (match-record x <foo>
(xyz)
#f)
While executing meta-command:
Syntax error:
unknown file:12066:34: lookup-field: unknown record type field in subform xyz
of (lookup-field xyz (+ 1 (+ 1 0)) ())
--8<---------------cut here---------------end--------------->8---
I changed a few services that were using ‘match’ to use either
‘match-record’ or accessors (the latter when accessing just one
or two fields).
This change breaks the ABI: we’ll have to run:
make clean-go && make
Thoughts?
Ludo’.
Ludovic Courtès (5):
records: 'match-record' checks fields at macro-expansion time.
doc: Recommend 'match-record'.
home: services: Use 'match-record' instead of 'match'.
services: base: Use 'match-record' instead of 'match'.
services: networking: Avoid 'match' on records.
doc/contributing.texi | 7 +-
gnu/home/services/mcron.scm | 58 +--
gnu/home/services/shells.scm | 50 +-
gnu/home/services/xdg.scm | 36 +-
gnu/services/base.scm | 882 +++++++++++++++++------------------
gnu/services/cuirass.scm | 4 +-
gnu/services/getmail.scm | 22 +-
gnu/services/networking.scm | 661 +++++++++++++-------------
guix/records.scm | 87 +++-
tests/records.scm | 33 ++
10 files changed, 967 insertions(+), 873 deletions(-)
base-commit: bb04b5e0ceb606c8d33d53bf06f7fc8855a2c56b
--
2.38.1
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#59390: [PATCH 0/5] Doing 'match-record' work at expansion time |
Date: |
Fri, 02 Dec 2022 00:07:42 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Ludovic Courtès <ludo@gnu.org> skribis:
> This addresses a longstanding issue: making ‘match-record’ efficient,
> and allowing it to error out on unknown field names at macro-expansion
> time.
I went ahead, rebased, and pushed these:
00ddf185e6 services: networking: Avoid 'match' on records.
adfe1064c8 services: base: Use 'match-record' instead of 'match'.
4c8eea027a home: services: Use 'match-record' instead of 'match'.
cc9ee514e3 doc: Recommend 'match-record'.
7c1161dba4 records: 'match-record' checks fields at macro-expansion time.
This change breaks the ABI: we’ll have to run:
make clean-go && make
Inquiries welcome!
Ludo’.
--- End Message ---