Skip to content

Instantly share code, notes, and snippets.

@sleibrock
Created February 18, 2022 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleibrock/52dcab51c8bd272fe0f4e8eda69cd837 to your computer and use it in GitHub Desktop.
Save sleibrock/52dcab51c8bd272fe0f4e8eda69cd837 to your computer and use it in GitHub Desktop.
Puts macro - a macro to print things and accept variadic arguments
(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