I'm trying to write a macro that substitutes some literal in an expression with a value,
such as (substitute 3 (+ 4 1 _ 1 5))
This is what I have so far,
(define-syntax substitute
(syntax-rules (_)
((substitute val (_ e1 ...))
(val e1 ...))
((substitute val (e1 _ e2 ...))
(e1 val e2 ...))
((substitute val (e1 e2 _ e3 ...))
(e1 e2 val e3 ...))))
How can I generalize this? Or really, how should I approach this?
Ok, I got a solution.
edit.
This is even better! It works with special constructs.