unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>,
	Guile User <guile-user@gnu.org>
Subject: Re: Macro for replacing a placeholder in an expression
Date: Thu, 28 Jul 2022 02:55:33 +0200	[thread overview]
Message-ID: <1ede5481-9d46-84e9-2530-d64ac835568b@telenet.be> (raw)
In-Reply-To: <80083c86-19b0-7537-be70-f763bd5b390f@posteo.de>


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

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.


[-- 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 --]

  reply	other threads:[~2022-07-28  0:55 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 [this message]
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
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=1ede5481-9d46-84e9-2530-d64ac835568b@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-user@gnu.org \
    --cc=zelphirkaltstahl@posteo.de \
    /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).