From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Massimiliano Gubinelli Newsgroups: gmane.lisp.guile.user Subject: Re: Looking For Advice On Updating Code From Guile 1.8.8 Date: Thu, 11 Feb 2021 08:53:08 +0100 Message-ID: References: <20210210214902.GN4066953@embecosm.com> Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24369"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Andrew Burgess Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Feb 11 08:53:29 2021 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 1lA6n2-0006FG-Tg for guile-user@m.gmane-mx.org; Thu, 11 Feb 2021 08:53:29 +0100 Original-Received: from localhost ([::1]:56564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lA6n1-0005sm-Sx for guile-user@m.gmane-mx.org; Thu, 11 Feb 2021 02:53:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lA6mn-0005sb-9f for guile-user@gnu.org; Thu, 11 Feb 2021 02:53:13 -0500 Original-Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:50853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lA6ml-0004lf-92 for guile-user@gnu.org; Thu, 11 Feb 2021 02:53:13 -0500 Original-Received: by mail-wm1-x336.google.com with SMTP id 190so4332587wmz.0 for ; Wed, 10 Feb 2021 23:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=xBla17NeiwabsTD6oZ0sHQ80BHAt+znzHfbmVWDlffU=; b=V8J1te0bECJ1Ss8floStp7mPHvb66ah4pL89l1sBc/JqKrdZT8cM0pNIUMQMfBlhHM NpnhPydY4i0Ggcdsvmdo+0wHUiW/oIrDW9DQUgjj70DnyaK7njYbT8uVZyF4Od8gsz6B RYfMEvEQPzIMTgbIWS8OOvVq4OLUGPQqFuYeR1uW6WtjZQi7X8T/mJ6ZHwkBDXmvVtkL P7NTr8mUF4RIqQrNgayZYG+rDCEZZkfmB+pybvt/kvUs5djprmzkGalh7z7S3SmSAsHK pbIGaz+OpZ82wAgp0XrTikQjU87bv3qOX+GyxBkbR8t1P7f5zWvwXgvBA/N9q29rjJwH MS5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=xBla17NeiwabsTD6oZ0sHQ80BHAt+znzHfbmVWDlffU=; b=bUz1UA0KcpoUcrZkcu93unWnPm0FVaWMkqpmKmaXGDqAIzdpUfymJMXXDXvhsx1F05 K7BoOGSddPTE9fXiNx+6Bf/GMgV/9ks5Y3CthwlYGC3z8GEmLWCwxC20uF8EdN7aIZM/ XMqchva8IwSbrGApydxJEj3jLGmOrh7/WvymZocRuOGGVdVLmDV8rkHwHd94Gb0EsC8H d0bOchrfAJ0GkO6jUNLgCcKCS3W8MZJBUkBB4tYTYb5GQqFb/drcNPXRIUz71sNxxfTL ym6Zh3++XlOcOuEh/94dc+uOi9O2koNYurTcxa1vLwAwRJHkpOFY7/FmBadNNU3y+WwH E9Xw== X-Gm-Message-State: AOAM533tYJAtSf6Kl7oA2L+q5WH4uVHxu1kvFYmZIhbd+/UVWsvECyK8 h7BNRiiU9AnKuSa8n0EtUv0= X-Google-Smtp-Source: ABdhPJxHtZYX3GBwXJ4qSzpiOMwb9NAcdw2MbO83mrOFkWIRLTfrfiJu6BKh1o5y8zILbXj2HBTFxg== X-Received: by 2002:a1c:d7:: with SMTP id 206mr3645443wma.68.1613029989425; Wed, 10 Feb 2021 23:53:09 -0800 (PST) Original-Received: from [192.168.0.10] ([78.192.22.137]) by smtp.gmail.com with ESMTPSA id c9sm8072619wmb.33.2021.02.10.23.53.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Feb 2021 23:53:08 -0800 (PST) In-Reply-To: <20210210214902.GN4066953@embecosm.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=m.gubinelli@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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:17241 Archived-At: Dear Andrew, in my experience in transitioning code from 1.8 to 2/3 (which have = essentially the same phasing model as far as I understand) you have to = keep in mind two things: 1) In Guile 1.8 macros are expanded only when needed (so for example = could do nontrivial computations at runtime), while now all macros go = away all at once and the compiled (and thus executed) code do not have = any macro. 2) all that it is needed for macro must be available beforehand, in = particular if you use regular procedures in macros either you define = them locally inside the macro or you have to wrap them in (eval-when = (expand compile load) .... ) forms. Note that this particular form = forces evaluation your code at least twice, so be aware of side effects. = E.g. try to put a (display ...) inside and see that it prints twice = (either at expand time and compile time or at expand time and load). = This would cure your problem when compiling the second file: (eval-when (expand compile load) (define (process-name name) (symbol-append name '-tail))) (defmacro blah (name) (let ((new-name (process-name name))) `(quote ,new-name))) but iif you use only the function inside the macro you could rewrite it = as (defmacro blah (name) (define (process-name name) (symbol-append name '-tail)) (let ((new-name (process-name name))) `(quote ,new-name))) or with a let and a lambda. This two remarks solve many problems, but again you could run into = issues if your program uses a lot of side-effects inside macros (e.g. to = populate tables of symbols). These side effects will happen at compile = time and the data could not be available anymore at runtime (because = Guile load the object file instead of reexpanding the macros). So for = example the program run ok the first time (because it is = expanded/compiled/executed) but not the second time (because then the = object file it is loaded from the cache and executed and no macro get = ever expanded again).=20 As far as I see there is no much difference between 2 and 3 so if you = manage to run on 2 it should run on 3. Hope this helps, Best Max > On 10. Feb 2021, at 22:49, Andrew Burgess = wrote: >=20 > Hello, >=20 > I'm in the process of updating a body of old code from guile 1.8.8 to > either guile 2 or 3. Ideally it would be great if the final code > could run on both version 2 and version 3. >=20 > When I first started looking at the problem I was hitting hundreds of > warnings like: >=20 > ..... warning: possibly unbound variable `blah' >=20 > along with lots of the expected unknown procedures as you might > expect. >=20 > So, I started working through the issues. In a (probably stupid) move > I started passing `--no-auto-compile' on the guile command line. > After a few days of hacking I actually managed to get the code running > again. >=20 > But then I remembered about the `--no-auto-compile' and figured I > should probably remove that. At which point I ran into a few > problems. >=20 > Here's a small (contrived) example, which I think is representative of > at least the first big problem I need to work around. Imagine two > files: >=20 > --- START: loader.scm --- >=20 > (define (load-files) > (load "loadee.scm")) >=20 > (load-files) >=20 > (display (blah abc)) > (newline) > (newline) >=20 > --- END: loader.scm --- >=20 > --- START: loadee.scm --- >=20 > (define (process-name name) > (symbol-append name '-tail)) >=20 > (defmacro blah (name) > (let ((new-name (process-name name))) > `(quote ,new-name))) >=20 > --- END: loadee.scm --- >=20 > This works fine when run as: >=20 > guile --no-auto-compile -s loader.scm >=20 > But, when with the compiler I get: >=20 > $ guile -s loader.scm > ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=3D0 > ;;; or pass the --no-auto-compile argument to disable. > ;;; compiling /tmp/loader.scm > ;;; /tmp/loader.scm:6:9: warning: possibly unbound variable `blah' > ;;; /tmp/loader.scm:6:9: warning: possibly unbound variable `abc' > ;;; compiled > ;;; compiling /tmp/loadee.scm > ;;; compiled > Backtrace: > 5 (apply-smob/1 #) > In ice-9/boot-9.scm: > 705:2 4 (call-with-prompt _ _ #) > In ice-9/eval.scm: > 619:8 3 (_ #(#(#))) > In ice-9/boot-9.scm: > 2312:4 2 (save-module-excursion _) > 3832:12 1 (_) > In /tmp/loader.scm: > 4:0 0 (_) >=20 > /tmp/loader.scm:4:0: In procedure module-lookup: Unbound variable: = abc >=20 > My understanding of what's happening here is that macros are expanded > at compile time, while load is a run-time thing, which is happening > after compilation. Hence why 'blah' and 'abc' are considered possibly > undefined. >=20 > Then in the compiled code the '(blah abc)' has not been macro > expanded, and so the argument is first being evaluated, which leads to > the error. >=20 > I read the manual on 'Local Inclusion'[1] and this seems to line up > with my understanding of the problem. It even makes special mention > that using (include "...") instead of (load "....") will allow for the > loadee to provide macros to the loader. >=20 > One problem is that the program, as its currently written, makes > significant use of the run-time nature of load in order to configure > the program state. >=20 > If I do switch to using (include "...") then I run into problems with > the macros, as in loadee, where the macro blah makes use of > process-names. Which again (as I understand it), at macro expand time > process-names will not be defined, and so this causes problems. >=20 > It feels frustratingly close that I can run the program with the > compiler off, but not with it on. I suspect there's still some way to > go in order to make things really guile 2/3 ready. So, is it possible > for me to force the compiler off from within the program itself? This > would allow me to make a first step from 1.8.8 to 2/3 (compiler off), > and then work on moving to compiler on after that. >=20 > Finally, I assume the model for how guile loads, expands, executes > changed between v1 and v2. Is there any specific hints/tips for how > to make the transition? >=20 > Any help and advice offered would be gratefully received. >=20 > Thanks, > Andrew >=20 > [1] = https://www.gnu.org/software/guile/manual/guile.html#Local-Inclusion >=20