What does the . in (define-syntax-rule (id . pattern) template) mean? Is it just part of the define-syntax-rule syntax or does it mean something special in racket?
It's standard variable arguments syntax for definitions (it's the same for procedures): all the identifiers after the name and before the dot are treated as required parameters, and after the dot comes a variable length list (with zero or more elements) with the optional parameters. For example:
(define (test x . args)
(displayln x)
(displayln args))
(test)
=> arity mismatch, the expected number of arguments
does not match the given number
(test 1)
=> 1
()
(test 1 2)
=> 1
(2)
(test 1 2 3)
=> 1
(2 3)
It's possible to have zero required parameters, making all of the parameters optional:
(define (test . args)
(displayln args))
(test)
=> ()
(test 1)
=> (1)
(test 1 2)
=> (1 2)
In the case of define-syntax-rule, this means that after the id zero or more patterns are expected:
(define-syntax-rule (id . pattern) template)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With