unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: 宋文武 <iyzsong@member.fsf.org>
Cc: guix-devel@gnu.org
Subject: Re: Change defaults of 'define-record-type*' need invalidate auto-compilation caches
Date: Mon, 08 Jan 2018 11:37:27 +0100	[thread overview]
Message-ID: <87po6khc0o.fsf@gnu.org> (raw)
In-Reply-To: <87o9m7m3es.fsf@member.fsf.org> ("宋文武"'s message of "Sat, 06 Jan 2018 23:07:39 +0800")

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’.

  reply	other threads:[~2018-01-08 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2018-01-08 12:49     ` 宋文武

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87po6khc0o.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=iyzsong@member.fsf.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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).