* Change defaults of 'define-record-type*' need invalidate auto-compilation caches
@ 2018-01-06 14:55 宋文武
2018-01-06 15:07 ` 宋文武
0 siblings, 1 reply; 4+ messages in thread
From: 宋文武 @ 2018-01-06 14:55 UTC (permalink / raw)
To: guix-devel
Hello,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Change defaults of 'define-record-type*' need invalidate auto-compilation caches
2018-01-06 14:55 Change defaults of 'define-record-type*' need invalidate auto-compilation caches 宋文武
@ 2018-01-06 15:07 ` 宋文武
2018-01-08 10:37 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: 宋文武 @ 2018-01-06 15:07 UTC (permalink / raw)
To: guix-devel
> Hello,
Send it by mistake...
For example, in the current directory, I have 'foo.scm':
--8<---------------cut here---------------start------------->8---
(define-module (foo)
#:use-module (guix records)
#:export (foo foo-x))
(define-record-type* <foo>
foo make-foo foo?
(x foo-x (default "x")))
--8<---------------cut here---------------end--------------->8---
And 'x.scm':
--8<---------------cut here---------------start------------->8---
(use-modules (foo))
(display (foo-x (foo)))
--8<---------------cut here---------------end--------------->8---
Run 'guile -L . x.scm', will output "x".
Then I change the '(default "x")' to '(default "y")' in foo.scm, and
re-run 'guile -L x.scm', it still output "x", I would expect it to
change to "y".
Only with '--fresh-auto-compile' or delete the cache of x.scm, I will
get the output "y".
Is this a bug?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Change defaults of 'define-record-type*' need invalidate auto-compilation caches
2018-01-06 15:07 ` 宋文武
@ 2018-01-08 10:37 ` Ludovic Courtès
2018-01-08 12:49 ` 宋文武
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2018-01-08 10:37 UTC (permalink / raw)
To: 宋文武; +Cc: guix-devel
Hi!
iyzsong@member.fsf.org (宋文武) skribis:
> For example, in the current directory, I have 'foo.scm':
>
> (define-module (foo)
> #:use-module (guix records)
> #:export (foo foo-x))
>
> (define-record-type* <foo>
> foo make-foo foo?
> (x foo-x (default "x")))
>
>
>
> And 'x.scm':
>
> (use-modules (foo))
> (display (foo-x (foo)))
>
>
> Run 'guile -L . x.scm', will output "x".
>
> Then I change the '(default "x")' to '(default "y")' in foo.scm, and
> re-run 'guile -L x.scm', it still output "x", I would expect it to
> change to "y".
>
> Only with '--fresh-auto-compile' or delete the cache of x.scm, I will
> get the output "y".
>
> Is this a bug?
It’s a feature. :-)
Namely, default value resolution happens at macro-expansion time:
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(guix records)
scheme@(guile-user)> (define-record-type* <foo>
foo make-foo foo?
(x foo-x (default "x")))
scheme@(guile-user)> ,expand (foo)
$2 = (let* ((x "x")
(s ((@@ (srfi srfi-9) allocate-struct) <foo> 1)))
((@@ (srfi srfi-9) struct-set!) s 0 x)
s)
--8<---------------cut here---------------end--------------->8---
That way, we can check at macro-expansion time that all the required
fields are present, which is nice.
The downside is what you write: that everything that uses the record
type must be recompiled when it is changed (IOW, the record type is part
of the ABI).
HTH!
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Change defaults of 'define-record-type*' need invalidate auto-compilation caches
2018-01-08 10:37 ` Ludovic Courtès
@ 2018-01-08 12:49 ` 宋文武
0 siblings, 0 replies; 4+ messages in thread
From: 宋文武 @ 2018-01-08 12:49 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guix-devel
ludo@gnu.org (Ludovic Courtès) writes:
> Hi!
>
> iyzsong@member.fsf.org (宋文武) skribis:
>
>> [...]
>>
>> Only with '--fresh-auto-compile' or delete the cache of x.scm, I will
>> get the output "y".
>>
>> Is this a bug?
>
> It’s a feature. :-)
>
> Namely, default value resolution happens at macro-expansion time:
>
> scheme@(guile-user)> ,use(guix records)
> scheme@(guile-user)> (define-record-type* <foo>
> foo make-foo foo?
> (x foo-x (default "x")))
>
> scheme@(guile-user)> ,expand (foo)
> $2 = (let* ((x "x")
> (s ((@@ (srfi srfi-9) allocate-struct) <foo> 1)))
> ((@@ (srfi srfi-9) struct-set!) s 0 x)
> s)
>
> That way, we can check at macro-expansion time that all the required
> fields are present, which is nice.
>
> The downside is what you write: that everything that uses the record
> type must be recompiled when it is changed (IOW, the record type is part
> of the ABI).
>
> HTH!
Get it, thanks for the explanation!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-08 12:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-06 14:55 Change defaults of 'define-record-type*' need invalidate auto-compilation caches 宋文武
2018-01-06 15:07 ` 宋文武
2018-01-08 10:37 ` Ludovic Courtès
2018-01-08 12:49 ` 宋文武
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.