From: Andrew Tropin <andrew@trop.in>
To: Attila Lendvai <attila@lendvai.name>
Cc: guile-devel@gnu.org
Subject: Re: Define works different when Compile and Eval
Date: Fri, 21 Jun 2024 16:33:42 +0400 [thread overview]
Message-ID: <87r0cq8ogp.fsf@trop.in> (raw)
In-Reply-To: <JWGBfCtR_R9VIAQomC7o9HI_pROABKhgc48qXZkTT_gJZcVmx9NSuJgNv-fW1gtnEp1K-ofrMeWwyjl0daeOwhxRdC7FQqahC1AeXB0t8LA=@lendvai.name>
[-- Attachment #1: Type: text/plain, Size: 1898 bytes --]
On 2024-06-19 09:53, Attila Lendvai wrote:
>> (define (test-eval teval)
>> (teval '(define a 1))
>
> if you want this^ to be actually defined while compilation is
> happening (i.e. in the compilation stage; see staged computing), then
> you need to use an (eval-when (expand) ...) wrapper around it.
Thank you for the reply! Not sure what you mean. The following code
defines `a`:
--8<---------------cut here---------------start------------->8---
(define (test-eval teval)
(teval '(define a 1))
(format #t "a value with ~a is ~a\n" teval (teval 'a)))
(test-eval peval)
(test-eval primitive-eval)
(exit 0)
;; a value with #<procedure peval (e)> is 1
;; a value with #<procedure primitive-eval (exp)> is 1
--8<---------------cut here---------------end--------------->8---
The problem and the difference is in how `(define a a)` is evaluated by
compile.
>
> https://www.gnu.org/software/guile/manual/guile.html#Eval-When
>
> compile does not evaluate (aka load) the definitions, it only compiles them.
compile returns value by default, which is probably means that
everything is loaded as well.
> alternatively, you yourself can explicitly call the lambda returned by compile.
--8<---------------cut here---------------start------------->8---
(use-modules (system base compile)
(system vm loader))
(define (peval e)
((load-thunk-from-memory
(compile
e
#:to 'bytecode
#:env (resolve-module
'(2024-06-18-define-bug))))))
--8<---------------cut here---------------end--------------->8---
It works the same way as the original code :(
>
> --
> • attila lendvai
> • PGP: 963F 5D5F 45C7 DFCD 0A39
> --
> “A politician is someone asking you to trust them more with power than they trust you with freedom...”
> — Kelly Diamond
>
>
>
--
Best regards,
Andrew Tropin
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2024-06-21 12:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-19 9:04 Define works different when Compile and Eval Andrew Tropin
2024-06-19 9:53 ` Attila Lendvai
2024-06-21 12:33 ` Andrew Tropin [this message]
2024-06-22 12:57 ` Attila Lendvai
2024-06-22 16:45 ` Maxime Devos
2024-06-21 14:40 ` Maxime Devos
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=87r0cq8ogp.fsf@trop.in \
--to=andrew@trop.in \
--cc=attila@lendvai.name \
--cc=guile-devel@gnu.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.
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).