[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Expanding ellipsis on lists of different length
From: |
Elf |
Subject: |
Re: [Chicken-users] Expanding ellipsis on lists of different length |
Date: |
Wed, 27 Aug 2008 12:02:05 -0700 (PDT) |
On Wed, 27 Aug 2008, Tobia Conforto wrote:
(define-syntax test
(syntax-rules ()
((test (a ...) (b ...))
(quote ((a b) ...)))))
What happens if one calls this macro on two lists of different lengths?
According to various online tutorials, the expansion should abort with an
error. In current hygienic Chicken the behaviour depends on which list ends
first:
i believe that this is an error in chicken. there are two ellipses in the
pattern and only one in the output spec, so in both cases it should error with
an invalid transformer spec notice. additionally, the 'a' isnt followed by
an ellipsis, nor is the 'b' followed by an ellipsis, which is specifically
the error referred to here: 'pattern variables that occur in
subpatterns followed by one or more instances of the identifier ... are
allowed only in subtemplates that are followed by as many instances of ... .
they are replaced in the output by all of the subforms they match in the input,
distributed as indicated. it is an error if the output cannot be built as
specified.'
(test (1 2) (10 20 30))
=> ((1 10) (2 20))
(test (1 2 3) (10 20))
Error: (map) during expansion of (test ...) - lists are not of same length:
(())
R5RS is pretty vague, but does hint at an error condition in the last
sentence:
"Pattern variables that occur in subpatterns followed by one or more
instances of the identifier ... are allowed only in subtemplates that are
followed by as many instances of .... They are replaced in the output by all
of the subforms they match in the input, distributed as indicated. It is an
error if the output cannot be built up as specified."
imho this isnt vague at all. conceptually, this means you cant drop out tails
arbitrarily, nor reattach them arbitrarily. (it does leave open the question
if '((test (a b ...) c ...) (test a c ...))' is valid, though. (or even
if the transformer was just 'a', for that matter.)
-elf