Created
January 8, 2015 17:18
-
-
Save tonyfischetti/c5230e63a97d0f1797fe to your computer and use it in GitHub Desktop.
Nested macros?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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