unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Does the eval-when example work?
@ 2022-10-19 20:32 Vivien Kraus
  2022-10-19 20:47 ` Jean Abou Samra
  2022-10-20  8:53 ` Maxime Devos
  0 siblings, 2 replies; 5+ messages in thread
From: Vivien Kraus @ 2022-10-19 20:32 UTC (permalink / raw)
  To: guile-user

Dear guile users,

The manual, section 6.8.8, presents the eval-when form with an example:

(use-modules (srfi srfi-19))
(eval-when (expand load eval)
  (define (date) (date->string (current-date))))
(define-syntax %date (identifier-syntax (date)))
(define *compilation-date* %date)

I take the liberty to add:

(display *compilation-date*)
(newline)

Now, when I save to test.scm and run guile -s test.scm, it gets
compiled and it displays the current date. However, if I run this
command a second time, the file is not recompiled, but the compilation
date changes. Is it intended?

If so, this is not exactly what I am looking for. I am looking for a
way to run the (date) form during the compilation phase, and save the
date to the compilation unit so that it does not change. Is this
possible?

Best regards,

Vivien



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Does the eval-when example work?
  2022-10-19 20:32 Does the eval-when example work? Vivien Kraus
@ 2022-10-19 20:47 ` Jean Abou Samra
  2022-10-22 13:26   ` Jean Abou Samra
  2022-10-20  8:53 ` Maxime Devos
  1 sibling, 1 reply; 5+ messages in thread
From: Jean Abou Samra @ 2022-10-19 20:47 UTC (permalink / raw)
  To: Vivien Kraus, guile-user

Le 19/10/2022 à 22:32, Vivien Kraus a écrit :
> Dear guile users,
>
> The manual, section 6.8.8, presents the eval-when form with an example:
>
> (use-modules (srfi srfi-19))
> (eval-when (expand load eval)
>    (define (date) (date->string (current-date))))
> (define-syntax %date (identifier-syntax (date)))
> (define *compilation-date* %date)
>
> I take the liberty to add:
>
> (display *compilation-date*)
> (newline)
>
> Now, when I save to test.scm and run guile -s test.scm, it gets
> compiled and it displays the current date. However, if I run this
> command a second time, the file is not recompiled, but the compilation
> date changes. Is it intended?
>
> If so, this is not exactly what I am looking for. I am looking for a
> way to run the (date) form during the compilation phase, and save the
> date to the compilation unit so that it does not change. Is this
> possible?



This code is behaving as expected. The manual's description of the example
and the naming "*compilation-date*" look buggy, however. It claims that the
code works in the REPL but not in a file, whereas the code does work in 
a file.
identifier-syntax just makes a macro that replaces an identifier with
some form. The code you quote just expands to the same as

(use-modules (srfi srfi-19))
(define (date)
   (date->string (current-date))
(define *compilation-date* (date))
(display *compilation-date*)
(newline)

On the other hand, if you define a macro that doesn't expand to the
function call "(date)" but to the result of this function call at
the time of compilation, it does work as a compilation timestamp
(and eval-when becomes really necessary).

(use-modules (srfi srfi-19))
(eval-when (expand load eval)
   (define compilation-start-date (date->string (current-date))))
(define-syntax *compilation-date*
   (lambda (sintax)
     (datum->syntax sintax compilation-start-date)))

(display *compilation-date*)
(newline)


Best,
Jean





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Does the eval-when example work?
  2022-10-19 20:32 Does the eval-when example work? Vivien Kraus
  2022-10-19 20:47 ` Jean Abou Samra
@ 2022-10-20  8:53 ` Maxime Devos
  2022-10-21 17:41   ` Vivien Kraus
  1 sibling, 1 reply; 5+ messages in thread
From: Maxime Devos @ 2022-10-20  8:53 UTC (permalink / raw)
  To: Vivien Kraus, guile-user


[-- Attachment #1.1.1: Type: text/plain, Size: 572 bytes --]



On 19-10-2022 22:32, Vivien Kraus wrote:
> Dear guile users,
> 
> The manual, section 6.8.8, presents the eval-when form with an example:
>
 > [...]
> 
> If so, this is not exactly what I am looking for. I am looking for a
> way to run the (date) form during the compilation phase, and save the
> date to the compilation unit so that it does not change. Is this
> possible?

I don't know the answer, but for (bit-for-bit) reproducibility, please 
support something like 
<https://reproducible-builds.org/docs/source-date-epoch/>.

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Does the eval-when example work?
  2022-10-20  8:53 ` Maxime Devos
@ 2022-10-21 17:41   ` Vivien Kraus
  0 siblings, 0 replies; 5+ messages in thread
From: Vivien Kraus @ 2022-10-21 17:41 UTC (permalink / raw)
  To: Maxime Devos, guile-user

Le jeudi 20 octobre 2022 à 10:53 +0200, Maxime Devos a écrit :
>  If so, this is not exactly what I am looking for. I am looking for a
> > way to run the (date) form during the compilation phase, and save
> > the
> > date to the compilation unit so that it does not change. Is this
> > possible?
> 
> I don't know the answer, but for (bit-for-bit) reproducibility,
> please 
> support something like 
> <https://reproducible-builds.org/docs/source-date-epoch/>.

I have to confess, I lied to you. I’m not interested in the compilation
date. What I want is to encode the typelib path at compile time, so I
can tell guile-gi where to find the typelibs (including the recursive
pkg-config requirements). Now that I know how to do that, I don’t have
to propagate any inputs, and I don’t have to keep pkg-config around at
run-time (except if the compilation cache gets invalidated, but who
does that).



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Does the eval-when example work?
  2022-10-19 20:47 ` Jean Abou Samra
@ 2022-10-22 13:26   ` Jean Abou Samra
  0 siblings, 0 replies; 5+ messages in thread
From: Jean Abou Samra @ 2022-10-22 13:26 UTC (permalink / raw)
  To: Vivien Kraus, guile-user



Le 19/10/2022 à 22:47, Jean Abou Samra a écrit :
> This code is behaving as expected. The manual's description of the 
> example
> and the naming "*compilation-date*" look buggy, however.

I've submitted a patch to fix this.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58646

Best,
Jean





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-22 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 20:32 Does the eval-when example work? Vivien Kraus
2022-10-19 20:47 ` Jean Abou Samra
2022-10-22 13:26   ` Jean Abou Samra
2022-10-20  8:53 ` Maxime Devos
2022-10-21 17:41   ` Vivien Kraus

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