unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Paul Jarc <prj@case.edu>, guile-user@gnu.org
Subject: Re: defining macros within eval
Date: Sun, 16 Oct 2022 18:13:30 +0200	[thread overview]
Message-ID: <9cdae485-8806-b975-16bc-378633c0b951@telenet.be> (raw)
In-Reply-To: <ozkdlepgcdl0.fsf@webapps-d-2.tis.cwru.edu>


[-- Attachment #1.1.1: Type: text/plain, Size: 1216 bytes --]

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 #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  parent reply	other threads:[~2022-10-16 16:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16  9:39 defining macros within eval Paul Jarc
2022-10-16 14:07 ` Jean Abou Samra
2022-10-16 16:21   ` Maxime Devos
2022-10-16 16:13 ` Maxime Devos [this message]
2022-10-16 16:17 ` Maxime Devos
2022-10-19  8:42   ` Paul Jarc
2022-10-19 17:36     ` 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=9cdae485-8806-b975-16bc-378633c0b951@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-user@gnu.org \
    --cc=prj@case.edu \
    /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).