From: Han-Wen Nienhuys <hanwenn@gmail.com>
To: "Linus Björnstam" <linus.bjornstam@veryfast.biz>
Cc: guile-devel@gnu.org
Subject: Re: unhandled constant?
Date: Sat, 1 Feb 2020 10:54:01 +0100 [thread overview]
Message-ID: <CAOw_e7a9=qXLnNqp0GUaR496hJduGWeJ=yUCDj7+WCMNXP==Lg@mail.gmail.com> (raw)
In-Reply-To: <07e36ec2-0c0c-4786-9040-ffcb3418e0bb@www.fastmail.com>
Here is an example that shows better how things work, and what might
be the cause of my problems. Is it right that programmatically set
contents of "current-module" are not serialized into the compiled
file?
(define (run-at-compile-time cmd)
(module-define! (current-module) (string->symbol cmd) #t)
(format (current-error-port) "I-am-called-at-compile-time ~a\n" cmd))
(define (runtime-call cmd)
(format (current-error-port) "I-am-called-at-runtime ~a\n" cmd)
(format (current-error-port) "val ~a\n"
(module-ref (current-module) (string->symbol cmd))))
(defmacro foo (cmd . rest)
(run-at-compile-time cmd)
`(runtime-call ,cmd))
(foo "xy")
$ guile1.8 ew.scm
I-am-called-at-compile-time xy
I-am-called-at-runtime xy
val #t
this is compatible with 2.2 without compilation,
$ GUILE_AUTO_COMPILE=0 guile2.2 ew.scm
I-am-called-at-compile-time xy
I-am-called-at-runtime xy
val #t
but compilation fails
$ GUILE_AUTO_COMPILE=1 guile2.2 ew.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/hanwen/vc/lilypond/ew.scm
;;; WARNING: compilation of /home/hanwen/vc/lilypond/ew.scm failed:
;;; Unbound variable: run-at-compile-time
$ guild2.2 compile ew.scm
Backtrace:
In system/base/target.scm:
57:6 19 (with-target _ _)
In system/base/compile.scm:
..
Unbound variable: run-at-compile-time
If I encapsulate the run-at-compile-time definition with
(eval-when
(compile eval)
it works if I remove the module manipulation, but the module-ref
doesn't work. It looks like the settings from module-define! are not
serialized into the byte code, so I can't have code that relies on
correspondence between module-define driven from macros and module-ref
during evaluation.
[hanwen@localhost lilypond]$ guild2.2 compile ew.scm
I-am-called-at-compile-time xy
wrote `/home/hanwen/.cache/guile/ccache/2.2-LE-8-3.A/home/hanwen/vc/lilypond/ew.scm.go'
[hanwen@localhost lilypond]$ GUILE_AUTO_COMPILE=0 guile2.2 ew.scm
I-am-called-at-runtime xy
Backtrace:
6 (apply-smob/1 #<catch-closure 56514b4c37a0>)
In ice-9/boot-9.scm:
705:2 5 (call-with-prompt ("prompt") #<procedure 56514b4d5c60 …> …)
In ice-9/eval.scm:
619:8 4 (_ #(#(#<directory (guile-user) 56514b591140>)))
In ice-9/boot-9.scm:
2312:4 3 (save-module-excursion #<procedure 56514b54b330 at ice-…>)
3832:12 2 (_)
In ew.scm:
10:10 1 (runtime-call "xy")
In unknown file:
0 (scm-error misc-error #f "~A ~S ~S ~S" ("No variabl…" …) …)
ERROR: In procedure scm-error:
No variable named xy in #<directory (guile-user) 56514b591140>
On Fri, Jan 31, 2020 at 9:01 PM Linus Björnstam
<linus.bjornstam@veryfast.biz> wrote:
>
> Read the docs. That seems to be a documentation bug. Try fiddling with the arguments to eval when and see if you can make it work.
>
> --
> Linus Björnstam
>
> On Fri, 31 Jan 2020, at 20:17, Han-Wen Nienhuys wrote:
> > On Fri, Jan 31, 2020 at 7:20 PM Linus Björnstam
> > <linus.bjornstam@veryfast.biz> wrote:
> > > I don't really understand your question. With defmacro and syntax-case you can run arbitrary code. If you just output code that does module-define! that won't be run until runtime, and thus you cannot depend on the result of that module-define! during expansion. You can however wrap it in an eval-when to solve that issue. That allows you to specify when code gets run. With module-define! I personally find it all a bit icky, but I usually stay as far away from phasing as I can :)
> >
> > eval-when looks like it might be a solution to the puzzle , but
> > honestly, the doc at
> >
> > https://www.gnu.org/software/guile/manual/html_node/Eval-When.html
> >
> > has me mystified. When I run the example through guile 2.2 and
> > display *compilation-date*,
> >
> > I get a different answer each time. Shouldn't it be a fixed timestamp
> > (of when the compile happened?)
> >
> > [hanwen@localhost lilypond]$ guile2.2 e.scm
> > ;;; note: source file /home/hanwen/vc/lilypond/e.scm
> > ;;; newer than compiled
> > /home/hanwen/.cache/guile/ccache/2.2-LE-8-3.A/home/hanwen/vc/lilypond/e.scm.go
> > ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> > ;;; or pass the --no-auto-compile argument to disable.
> > ;;; compiling /home/hanwen/vc/lilypond/e.scm
> > ;;; compiled
> > /home/hanwen/.cache/guile/ccache/2.2-LE-8-3.A/home/hanwen/vc/lilypond/e.scm.go
> > Fri Jan 31 20:15:57+0100 2020
> > [hanwen@localhost lilypond]$ guile2.2 e.scm
> > Fri Jan 31 20:15:58+0100 2020
> > [hanwen@localhost lilypond]$ guile2.2 e.scm
> > Fri Jan 31 20:16:00+0100 2020
> >
> > --
> > Han-Wen Nienhuys - hanwenn@gmail.com - http://www.xs4all.nl/~hanwen
> >
--
Han-Wen Nienhuys - hanwenn@gmail.com - http://www.xs4all.nl/~hanwen
next prev parent reply other threads:[~2020-02-01 9:54 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 23:08 unhandled constant? Han-Wen Nienhuys
2020-01-29 15:06 ` Ricardo Wurmus
2020-01-30 8:05 ` Han-Wen Nienhuys
2020-01-31 10:49 ` Han-Wen Nienhuys
2020-01-31 11:17 ` Ricardo Wurmus
2020-02-02 19:30 ` Jan Nieuwenhuizen
2020-01-31 14:57 ` Linus Björnstam
2020-01-31 15:16 ` Han-Wen Nienhuys
2020-01-31 17:50 ` Han-Wen Nienhuys
2020-01-31 18:19 ` Linus Björnstam
2020-01-31 19:17 ` Han-Wen Nienhuys
2020-01-31 19:52 ` Linus Björnstam
2020-01-31 20:01 ` Linus Björnstam
2020-02-01 9:54 ` Han-Wen Nienhuys [this message]
2020-02-01 9:56 ` Han-Wen Nienhuys
2020-02-01 10:10 ` David Kastrup
2020-02-01 11:23 ` Han-Wen Nienhuys
2020-02-01 11:36 ` David Kastrup
2020-02-01 13:12 ` Linus Björnstam
2020-02-01 11:09 ` David Kastrup
2020-02-01 13:16 ` Linus Björnstam
2020-02-01 14:23 ` David Kastrup
2020-02-01 15:21 ` Linus Björnstam
2020-02-01 21:55 ` Taylan Kammer
2020-02-01 21:58 ` Fwd: " Taylan Kammer
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://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOw_e7a9=qXLnNqp0GUaR496hJduGWeJ=yUCDj7+WCMNXP==Lg@mail.gmail.com' \
--to=hanwenn@gmail.com \
--cc=guile-devel@gnu.org \
--cc=linus.bjornstam@veryfast.biz \
/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.
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).