Skip to content

Instantly share code, notes, and snippets.

@tonyfischetti
Created January 8, 2015 17:18
Show Gist options
  • Save tonyfischetti/c5230e63a97d0f1797fe to your computer and use it in GitHub Desktop.
Save tonyfischetti/c5230e63a97d0f1797fe to your computer and use it in GitHub Desktop.
Nested macros?
(define (add6 n)
(+ 6 n))
(define (return5)
5)
;I want to create a macro (or series of macros) that will expand this:
(>>
(return5)
(add6)
(display))
;into this:
(display (add6 (return5)))
;I have the following macro:
(define-syntax >>a
(syntax-rules ()
((_ ((this ...) ())) (this ...))
((_ ((this ...) . (that ...)) ) (this ... (>>a (that ...))))))
;That makes this form work:
(>>a
((display)
(add6)
(return5)
()))
;Now all I have to do is write a macro to reverse the order of the functions
(define-syntax >>b
(syntax-rules ()
((_ (this ...)) (reverse (this ...))) ))
;Now, to put it all together, I use
(>>a
(>>b
(()
(return5)
(add6)
(add6)
(display))))
; But it doesn't work, no matter what I try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment