4 ms·
Have you read about macros in Scheme/Racket? For example, with define-syntax-rule you can define a rule to transform code that looks like code. (define-synta
by gus_massa 5y ago
Have you read about macros in Scheme/Racket? For example, with define-syntax-rule you can define a rule to transform code that looks like code.
(define-syntax-rule (repeat3 body ...)
(begin
body
body
body))
and you just use it
(repeat3 (print "Hello!"))
expands to
(begin
(print "Hello!")
(print "Hello!")
(print "Hello!"))
and the output is
Hello!Hello!Hello!
- scotty79 5y agoThat seems like a simple substitution. The body in your example is AST sub tree. What I want to do, is check it for occurence of some (multi-node) patterns and alter it so that those patterns transform into some other target patterns. I would like to be able to specify those patterns in declarative manner. Same way I describe transformations in xslt to transform one xml file into different similar xml file. I could, in lisp macro, convert ast of `body` to xml tree, write xslt, apply it to that xml, convert back resulting xml into lisp ast and return if from macro. But that seems like a bit of overkill. I'm searching for something that does descrptive tree transformations similar to xslt but more lightweight. More suitable for use in writing macros.