1
votes

I am writing a function annotate that uses match-lambda often with recursive calls to annotate. Here is one of the patterns and matches:

(`(,<param> . ,<params> (lambda (,<args>) ,<stmt> . ,<stmts>))
 `(CLOSURE ENV ,(append (append `(,<param>) `(,<params>))`(,<args>)) (lambda (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))

I am getting a complaint that the first use of "." is illegal -- between "param" and "params" -- but I can't figure out why. This pattern and match doesn't get any complaints and seems very similar with regards to the first ".":

(`(λ (,<param1> . ,<params>) ,<stmt> . ,<stmts>)
 `(CLOSURE ENV ,(map annotate `(,<param1> . ,<params>)) (λ (ENV) ,(map annotate `(,<stmt> . ,<stmts>)))))

Any advice is appreciated.

Thanks.

1

1 Answers

1
votes

The . needs to be before the last element in the list (except for some Racket-specific syntax that you are not using). Remember that the general form of a list is (a b c . d), meaning (cons a (cons b (cons c d))). You might be able to use ,@<params> to match some elements in the middle of a list, but I am not sure about that.