guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Change defaults of 'define-record-type*' need invalidate auto-compil


From: Ludovic Courtès
Subject: Re: Change defaults of 'define-record-type*' need invalidate auto-compilation caches
Date: Mon, 08 Jan 2018 11:37:27 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Hi!

address@hidden (宋文武) 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’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]