From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Maxime Devos <maximedevos@telenet.be>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Macro for replacing a placeholder in an expression
Date: Thu, 28 Jul 2022 10:23:48 +0000 [thread overview]
Message-ID: <a2ea28e1-69f9-5fc4-e856-2f9b8e51f7a9@posteo.de> (raw)
In-Reply-To: <1ede5481-9d46-84e9-2530-d64ac835568b@telenet.be>
Hello Maxime!
On 7/28/22 02:55, Maxime Devos wrote:
>
> These macros all sound more complicated than necessary -- on the first one,
> I've sent you a message with sneek:
>
> ;; By: Maxime Devos
>
> ;; This does not recurse into #(...).
> ;; Also, such a construct does not nest well, you can't put a replace-result-placeholder inside a replace-result-placeholder meaningfully,
> ;; so I'm wondering why you're doing this, maybe your goal can be accomplished more robustly with a different method.
> (eval-when (expand load eval)
> (define (replace-placeholder new code) ; <--- recursively transforms code to replace '<?>' by new
> (syntax-case code (<?>)
> (<?> new)
> ((x . y)
> #`(#,(replace-placeholder new #'x) . #,(replace-placeholder new #'y)))
> (rest #'rest))))
>
> (define-syntax replace-result-placeholder
> (lambda (s)
> (syntax-case s (<?>) ; <?>: placeholder
> ((_ new code) (replace-placeholder #'new #'code)))))
>
> (display (replace-result-placeholder
> quote
> (<?> bar))) ; -> bar
>
> (I think thinking in terms of 'operations' and special-casing lambda etc would
> make things harder here)
>
> As a bonus, this supports things like `((x . <?>) (z . w)) which aren't
> supported by the original macro as that macro assumed lists.
>
> Greetings,
> Maxime.
>
I'll need to look at this and learn about eval-when. I also did not think about
vectors yet. Thank you!
Best regards,
Zelphir
--
repositories:https://notabug.org/ZelphirKaltstahl
next prev parent reply other threads:[~2022-07-28 10:23 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 [this message]
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
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=a2ea28e1-69f9-5fc4-e856-2f9b8e51f7a9@posteo.de \
--to=zelphirkaltstahl@posteo.de \
--cc=guile-user@gnu.org \
--cc=maximedevos@telenet.be \
/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).