Created
February 18, 2022 16:52
-
-
Save sleibrock/52dcab51c8bd272fe0f4e8eda69cd837 to your computer and use it in GitHub Desktop.
Puts macro - a macro to print things and accept variadic arguments
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
(require (for-syntax racket/base)) | |
(provide puts) | |
(define-syntax (puts stx) | |
(define datum (syntax->datum stx)) | |
(define args (cdr datum)) | |
(datum->syntax stx | |
(if (empty? args) | |
'(displayln "") | |
(if (= 1 (length args)) | |
(cons 'displayln args) | |
(cons 'displayln | |
(cons (cons 'format args) '())))))) | |
; test output | |
(module+ main | |
(puts) | |
(puts "Hello") | |
(puts "Hello ~a" "Steven")) | |
; end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment