chibi-scheme icon indicating copy to clipboard operation
chibi-scheme copied to clipboard

mis-matched lengths when expanding a syntax-rule

Open strtok opened this issue 2 years ago • 3 comments

(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))

strtok avatar Jan 25 '22 19:01 strtok

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.

mnieper avatar Jan 25 '22 21:01 mnieper

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.

strtok avatar Jan 25 '22 23:01 strtok

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.

ashinn avatar Jan 26 '22 00:01 ashinn