From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Abou Samra Newsgroups: gmane.lisp.guile.user Subject: Re: Does the eval-when example work? Date: Wed, 19 Oct 2022 22:47:47 +0200 Message-ID: <1bdfde63-f990-f3d6-5088-96b2d0fd07df@abou-samra.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38235"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 To: Vivien Kraus , guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Oct 19 22:48:35 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olFzN-0009lL-MV for guile-user@m.gmane-mx.org; Wed, 19 Oct 2022 22:48:33 +0200 Original-Received: from localhost ([::1]:57288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olFzM-00061g-IX for guile-user@m.gmane-mx.org; Wed, 19 Oct 2022 16:48:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olFyk-000602-1U for guile-user@gnu.org; Wed, 19 Oct 2022 16:47:54 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.133]:52525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olFyi-00065c-A3 for guile-user@gnu.org; Wed, 19 Oct 2022 16:47:53 -0400 Original-Received: from [10.188.149.104] ([46.193.67.184]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.168]) with ESMTPSA (Nemesis) id 1Mi2aH-1pGUBp2rmj-00e7OC; Wed, 19 Oct 2022 22:47:48 +0200 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:jRVHMAoYTv2Z+M06kHsc3rEULzle62+R7nEjpB+AvuKUvolhF10 uFzdnBEZKyXeMHJC1vizUsL6PBQwB9vI7Y8QpFnBbhVVBvIISAnl5NLbHydchsJelvWgjVt /Ro+R4uLbcZ82DaUwcmEFxVXg8AhDUKPHzGlNXByv0nev1MDns+EFpRGIdNz3cvJUkhjNqb 3VSh33C3BuF3np/LQUMug== X-UI-Out-Filterresults: notjunk:1;V03:K0:n7h6oC7D6uM=:3j2Nr/Ju/sb0Z8UJ4CSQ7B m8CSG18YZ+uTHBgKkQoxtBIXsTBhQvAt/re38q8ZIEGcLymJ3LVJZsAtSPmN3KVG0U1GhTorH pJgZit2u2BLbF/auXKZ10xVO+9MFXaGB0U3sA/eX4fdr4UmqtgSujCeH5XPREWumbpl9xesGC 9/4t5Bp8pfO6h+nhf2aF4Csxe6wwnhvtJyP+p3ThIechkOuxuFxN9tA9VrHPaFugk2TIk5T/i mZdIWA25KgiM0i7SyuAP5Ky5yWN7HpT5kZWnCmxTsrHd7iBv9z+aPVLpxgU6ii6PN2imZzOOr 7T38gTyRG5HJqceGxTz26f0iqNK4tzNLzJHthyx623LrCEvlrTV3coNSYiifhV0vI194e9Exy 44TU40z0nXlhVtZeN4K5Pbck9fLSHNWMo51wBZdeOgywRqzADCPhvGxfAsGRNwceu+pj9SY5L uYu/zAWtHWJv0l65Eq40TmKHEYhgyrnS8CR5FGh2vJj6HoiaWcXI3BK5vH3ueMfIqJOXt8sN+ 8ebD1EAHZ3geQ3khA/t03uO89NAKkWrVKU1TMz7OBanHY7vVkClw5HPsfr1WLzZlqLmbCnAOb a+5cKx1UhQBJ/HxKjSSowTZmj9BznIcioGEPCAymNkbKcmydkBIT0t7iFvLtkNS9vuhYzIVkw vMjumxomt852oMi0AyhSp6ZIN5O1dFDBq7mgBAWcFNaPt5pfWBmxRG6IASrULuFhSjcEJliQ7 xyXNuY4kznuolO7QGTJogYFWuHOxlXJdkn0enZ+Ok+fBnnj6vkq3q901yuxJlIfNU1LbQLY2 Received-SPF: none client-ip=212.227.126.133; envelope-from=jean@abou-samra.fr; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18665 Archived-At: 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