How to write a macro that receives any number of arguments and print them out?
(define-syntax prnt
(syntax-rules ()
[(prnt elem ...) (display (format "~a" elem .开发者_JAVA百科..))]
))
The above code run in racket will emit the following error:
format: format string requires 1 arguments, given 3; arguments were: "~a" "1" 2 3
then how can I achieve when use (prnt "1" 2 3), it can print any thing following prnt?
If you really want a macro:
(define-syntax prnt
(syntax-rules ()
[(prnt elem ...)
(begin (displayln elem) ...)]))
You don't need a macro if all you want is being able to display multiple objects with a single function call, though:
(define (prnt . args)
(for-each displayln args))
精彩评论