* I think thunked fields are breaking my previously working code
@ 2022-01-10 17:55 edk
2022-01-10 21:39 ` Ricardo Wurmus
0 siblings, 1 reply; 3+ messages in thread
From: edk @ 2022-01-10 17:55 UTC (permalink / raw)
To: help-guix
Dear Guixers
This is a follow-up on
https://lists.gnu.org/archive/html/help-guix/2022-01/msg00000.html
Using the REPL, I traced the bug on my code trying to update fields of
an operating-system records, which on gnu/system.scm are declared as
"thunked".
Guile is not my primary language. I would really appreciate some
pointers here:
- Why is it that I can't update those fields ?
- I was able to ~1 month ago, but can't do that now. Why ? Is my
use-case unsupported ? Should I expect other breaking change in the
future ? i.e. was I using a non-public interface ?
- How can I update those fields ?
For example, given that "minimal-container" is an operating system, I
can do the following:
(set-fields minimal-container ((operating-system-host-name) "toto"))
But not:
(set-fields minimal-container ((operating-system-label) "toto"))
while both fields are supposed to be strings, but label is "thunked".
Thanks in advance for any help.
Cheers,
Edouard.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: I think thunked fields are breaking my previously working code
2022-01-10 17:55 I think thunked fields are breaking my previously working code edk
@ 2022-01-10 21:39 ` Ricardo Wurmus
2022-02-27 20:35 ` Edouard Klein
0 siblings, 1 reply; 3+ messages in thread
From: Ricardo Wurmus @ 2022-01-10 21:39 UTC (permalink / raw)
To: edk; +Cc: help-guix
edk@beaver-labs.com writes:
> For example, given that "minimal-container" is an operating system, I
> can do the following:
>
> (set-fields minimal-container ((operating-system-host-name) "toto"))
>
> But not:
>
> (set-fields minimal-container ((operating-system-label) "toto"))
In Guile we usually try to avoid mutation like that. The records API
allows you to use inheritance instead:
(operating-system
(inherit minimal-container)
(label "toto"))
Thunking just means that the field is a procedure that returns a value
when called with no arguments. The records in (guix records) are not
plain SRFI9 records, so I would not expect set-fields to work at all.
--
Ricardo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: I think thunked fields are breaking my previously working code
2022-01-10 21:39 ` Ricardo Wurmus
@ 2022-02-27 20:35 ` Edouard Klein
0 siblings, 0 replies; 3+ messages in thread
From: Edouard Klein @ 2022-02-27 20:35 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: help-guix
Thank you so much Ricardo, you have no idea how big of a thorn you
removed from my side. I owe you one.
Ricardo Wurmus <rekado@elephly.net> writes:
> edk@beaver-labs.com writes:
>
>> For example, given that "minimal-container" is an operating system, I
>> can do the following:
>>
>> (set-fields minimal-container ((operating-system-host-name) "toto"))
>>
>> But not:
>>
>> (set-fields minimal-container ((operating-system-label) "toto"))
>
> In Guile we usually try to avoid mutation like that. The records API
> allows you to use inheritance instead:
>
> (operating-system
> (inherit minimal-container)
> (label "toto"))
>
> Thunking just means that the field is a procedure that returns a value
> when called with no arguments. The records in (guix records) are not
> plain SRFI9 records, so I would not expect set-fields to work at all.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-27 20:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 17:55 I think thunked fields are breaking my previously working code edk
2022-01-10 21:39 ` Ricardo Wurmus
2022-02-27 20:35 ` Edouard Klein
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).