* match-record
@ 2022-12-02 18:59 Aleksandr Vityazev
2022-12-02 21:45 ` match-record Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Aleksandr Vityazev @ 2022-12-02 18:59 UTC (permalink / raw)
To: guix-devel
Hi,
Before cc9ee514e37f6ec74dd9cab91a13d51f7b8d47e7 commit the code below
worked:
#+begin_src scheme :scheme guile :season guile
(define (iwd-etc-service config)
(match-record config <iwd-configuration> (config)
`(("iwd/main.conf"
,(apply mixed-text-file
"main.conf"
(serialize-ini-config config))))))
#+end_src
then this lead to an error:
Syntax error:
test.scm:109:44: lookup-field: unknown record type field in subform
config of (lookup-field config (+ 1 (+ 1 (+ 1 0))) ())
If you fix the code to the following one, it will work.
#+begin_src scheme :scheme guile :season guile
(define (iwd-etc-service cfg)
(match-record cfg <iwd-configuration> (config)
`(("iwd/main.conf"
,(apply mixed-text-file
"main.conf"
(serialize-ini-config config))))))
#+end_src
Should the code from the first block work, or should I not write it that
way?
--
Best regards,
Aleksandr Vityazev
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: match-record
2022-12-02 18:59 match-record Aleksandr Vityazev
@ 2022-12-02 21:45 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2022-12-02 21:45 UTC (permalink / raw)
To: Aleksandr Vityazev; +Cc: guix-devel
Hi Aleksandr,
Aleksandr Vityazev <avityazev@posteo.org> skribis:
> Before cc9ee514e37f6ec74dd9cab91a13d51f7b8d47e7 commit the code below
> worked:
>
> #+begin_src scheme :scheme guile :season guile
>
> (define (iwd-etc-service config)
> (match-record config <iwd-configuration> (config)
> `(("iwd/main.conf"
> ,(apply mixed-text-file
> "main.conf"
> (serialize-ini-config config))))))
> #+end_src
>
>
> then this lead to an error:
> Syntax error:
> test.scm:109:44: lookup-field: unknown record type field in subform
> config of (lookup-field config (+ 1 (+ 1 (+ 1 0))) ())
>
>
> If you fix the code to the following one, it will work.
>
> #+begin_src scheme :scheme guile :season guile
>
> (define (iwd-etc-service cfg)
> (match-record cfg <iwd-configuration> (config)
[...]
> Should the code from the first block work, or should I not write it that
> way?
You have to write it that way. (Though I would recommend a different
name for the field anyway, maybe ‘raw-file’?)
This is due to how “literals” are matched in syntax-{case,rules} (info
"(guile) Syntax Rules"):
A literal matches an input expression if the input expression is an
identifier with the same name as the literal, and both are unbound(1).
Here, because of the ‘config’ parameter, one of the two identifiers was
bound while the other is not, hence the match error.
HTH!
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-02 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-02 18:59 match-record Aleksandr Vityazev
2022-12-02 21:45 ` match-record Ludovic Courtès
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.