guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: defining macros within eval


From: Maxime Devos
Subject: Re: defining macros within eval
Date: Sun, 16 Oct 2022 18:13:30 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

On 16-10-2022 11:39, Paul Jarc wrote:
Hi.  I'm updating some old code to work with newer versions of Guile.
This example used to work with 1.8, but gives an error with 2.2 and
later:

(begin
   (eval '(define-syntax-rule (rule x) x) (current-module))
   (display (rule "ok\n")))

ERROR: Wrong type to apply: #<syntax-transformer rule>

The error happens for define-syntax-rule and define-macro, but not
plain define.  It happens when eval is within begin or let, but not at
the top level.  Is there some way to make this work?  In my real code,
the expression is read from a file, where it might be a macro
definition or anything else, and it's evaluated in a different module
from the current one.

Surround (eval ...) by (eval-when (expand) ...). Section '(guile)Eval-when' explains the 'why'. Depending on where you are using 'rule' and what the real 'rule' is, you might need the other 'load' and 'eval' as well.

IIUC, the previous 'lazy macros' (?) system of 1.8 (which didn't need the eval-when thing (?)) was rather impractical to do optimisation with, hence the more conventional 'eval-when' as found in other Schemes.

Greetings,
Maxime.

Attachment: OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]