chibi-scheme
chibi-scheme copied to clipboard
mis-matched lengths when expanding a syntax-rule
(tested on 0.10)
consider this macro:
(define-syntax zip-mult (syntax-rules () ((_ (x x* ...) (y y* ...)) (+ (* x y) (* x* y*) ...))))
Should an input that results in differing length expansions for x* and y* cause an error?
For example: (zip-mult (10 20 30 40) (10 20 30)) ignores the final matched x* and produces the same result as (zip-mult (10 20 30) (10 20 30))
An R7RS implementation like Chibi does not have to signal an error here. (An R6RS implementation would have to raise a syntax violation.) Chibi's behavior here is akin to R7RS's specification of map
, where the list arguments don't have to be of the same size but where map
stops iterating when the end of the shortest sequence is reached.
Thanks for the explanation. That seems reasonable. I did look at the R7 spec for syntax-rules and it was very unclear on what to do here.
R7 just doesn't specify this case, and since there's different behavior among implementations the best we could have done was call it out as "is an error".
It can be handy when you consciously take advantage of this but surprising when you make a mistake and it gets silently ignored. Maybe adding a warning here would be best for Chibi.