unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: guile-user@gnu.org
Subject: Re: Macro for replacing a placeholder in an expression
Date: Thu, 28 Jul 2022 03:04:20 +0200	[thread overview]
Message-ID: <0c9ca13b-5cda-b575-4645-2040bb30ea53@telenet.be> (raw)
In-Reply-To: <80083c86-19b0-7537-be70-f763bd5b390f@posteo.de>


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


On 28-07-2022 01:57, Zelphir Kaltstahl wrote:
> scheme@(guile-user)> (define-syntax test
>   (syntax-rules (lambda)
>     [(_ (op args body* ...))
>      ((test op) (test args) (test body* ...))]
>
>     [(_ thing1 thing2 things* ...)
>      ((test thing1) (test thing2 things* ...))]
>
>     [(_ (thing))
>      (thing)]
>
>     [(_ thing)
>      thing]))
> scheme@(guile-user)> (test (lambda (a) (+ a 1)))
> While compiling expression:
> Syntax error:
> unknown file:798:0: lambda: invalid argument list in subform ((a)) of 
> (test (a))
> ~~~~
>
> There seems to be something about a template like (one-thing) that I 
> do not understand or something completely different is going on. 

Here's what happening:

(test (lambda (a) (+ a 1))

--> because  the 'test' in the beginning is a macro

((test lambda) (test (a)) (test (+ a 1))

--> likewise

(lambda (test (a)) (test (+ a 1))

Now we end up with the 'lambda' macro. The lambda macro sees as argument 
list (test (a)) and interprets 'test' as the first argument, but the 
second part '(a)' is not an identifier so the lambda macro cannot do 
anything with that and tells you that by saying: lambda: invalid 
argument list in ....

This seems the same issue as in 'Re: boiler plate class generation, 
writing fresh variables with macros' to me but in a slightly different 
context

> Syntax transformations in Scheme work from the outside to the inside, 
> not the other way around, so you can't do things like this 
> (define-class doesn't know what to do with this 'slot-machine' thing, 
> it will reject it for not being a valid slot definition). However, you 
> can define a syntax that generates the surrounding define-class and 
> interprets things to insert the result of slot-matchine into a proper 
> define-class form. 
I consider a (in your case recursive, but in that case more like 
something like syntax-map (which can be defined recursively in terms of 
syntax-case)) syntax-case to be practical for this (more so than pure 
syntax-rules), see my other response.

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-07-28  1:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27 23:57 Macro for replacing a placeholder in an expression Zelphir Kaltstahl
2022-07-28  0:55 ` Maxime Devos
2022-07-28 10:23   ` Zelphir Kaltstahl
2022-07-28 10:28     ` Maxime Devos
2022-07-30 15:42     ` Zelphir Kaltstahl
2022-07-30 20:44       ` Maxime Devos
2022-07-30 21:10         ` Maxime Devos
2022-07-30 21:13       ` Maxime Devos
2022-08-05  9:42         ` Linus Björnstam
2022-08-06 14:28           ` Zelphir Kaltstahl
2022-07-28  1:04 ` Maxime Devos [this message]
2022-07-28  8:39   ` Zelphir Kaltstahl
2022-07-28  9:48     ` Maxime Devos
2022-07-28 11:26       ` Zelphir Kaltstahl

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=0c9ca13b-5cda-b575-4645-2040bb30ea53@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-user@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).