Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the dot mean here in racket?

Tags:

racket

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?

like image 538
JRR Avatar asked Dec 17 '25 14:12

JRR


1 Answers

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)
like image 136
Óscar López Avatar answered Dec 20 '25 22:12

Óscar López