;; 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.
OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature
