Re: [Chicken-users] Expanding ellipsis on lists of different length
On Wed, Aug 27, 2008 at 9:02 PM, Elf [EMAIL PROTECTED] wrote: 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.' BTW, alexpander accepts this form, but gives an error if the lists are of unequal length. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Expanding ellipsis on lists of different length
felix winkelmann wrote: alexpander accepts this form, but gives an error if the lists are of unequal length. I believe this is the correct behaviour. Chicken gives an error only when the first list is longer than the second, not when it's shorter. Elf wrote: the untest case is always valid, the test case is only valid when input is of the same length. Yes, that's my point. i am confused. are you proposing that it should always signal an error when getting the split ellipses like this, or when the lists are mismatched? (the second case is a bit unpleasant to try to catch all the time, and would probably have performance unplesantnesses.) It should signal an error when they are mismatched. I believe it's only a matter of using a version of map that checks this condition: that all its arguments become '() at the same time. Maybe it would be useful to modify map itself in this way? ;; correct, this is an error (map list '(1 2 3) '(10 20)) = Error: (map) lists are not of same length: (()) ;; not so correct, this should be an error too (map list '(1 2) '(10 20 30)) = ((1 10) (2 20)) Tobia ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Expanding ellipsis on lists of different length
On Thu, 28 Aug 2008, Tobia Conforto wrote: I believe it's only a matter of using a version of map that checks this condition: that all its arguments become '() at the same time. Maybe it would be useful to modify map itself in this way? ;; correct, this is an error (map list '(1 2 3) '(10 20)) = Error: (map) lists are not of same length: (()) ;; not so correct, this should be an error too (map list '(1 2) '(10 20 30)) = ((1 10) (2 20)) this is a problem, because this technically is correct behaviour, if we're going to allow this (what i consider broken but understand from my betters is merely unspecified) behaviour. it is consuming all of the tokens from the list. yay ambiguity. i dont think that trying to solve the case in the general form by the extra checks would be a good idea because a) most forms will be correct in more than an unspecified sense, and b) the vast majority of forms would get a fairly nasty slowdown in order to error for something outside the spec. -elf ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Expanding ellipsis on lists of different length
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 ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Expanding ellipsis on lists of different length
Elf wrote: Tobia Conforto wrote: (define-syntax test (syntax-rules () ((test (a ...) (b ...)) (quote ((a b) ...) 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. I beg to differ. This is a perfectly valid syntax-rule. The number of ellipses in the pattern doesn't need to match those in the template, not in this way. For example this is valid too--it does the opposite of test: (define-syntax untest (syntax-rules () ((untest (a b) ...) (quote ((a ...) (b ...)) (untest (1 10) (2 20) (3 30)) = ((1 2 3) (10 20 30)) 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. I think you are reading it wrong. Let's apply it to test: (define-syntax test (syntax-rules () ((test (a ...) (b ...)) (quote ((a b) ...) Pattern variables [for example, the 'b inside (b ...)] that occur in subpatterns [the same 'b is also the subpattern in this case] followed by one or more instances of the identifier ... [one instance] are allowed *only* in subtemplates [(a b) is the subtemplate] that are followed by as many instances of ... [again one instance.] Applied to untest: (define-syntax untest (syntax-rules () ((untest (a b) ...) (quote ((a ...) (b ...)) Pattern variables [for example, the 'a in (a b)] that occur in subpatterns [(a b) is the subpattern] followed by one or more instances of the identifier ... [one instance] are allowed *only* in subtemplates [the 'a inside (a ...) is the subtemplate] that are followed by as many instances of ... [again one instance.] AFAICS, the only possible error that can happen at macro expansion time, related to the ellipsis, is to take a macro combining several pattern-ellipses into one template-ellipsis (such as test above) and apply it to lists of different length. What I'm proposing is to always signal it as an error, not just half of the times. Tobia ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Expanding ellipsis on lists of different length
apparently its neither invalid nor valid. according to riastradh and others, if i understood correctly, such behaviour is not covered in r5rs at all, and some implementations do allow it , and some dont. the untest case is always valid, the test case is only valid when input is of the same length. i am confused. are you proposing that it should always signal an error when getting the split ellipses like this, or when the lists are mismatched? (the second case is a bit unpleasant to try to catch all the time, and would probably have performance unplesantnesses.) -elf On Wed, 27 Aug 2008, Tobia Conforto wrote: Elf wrote: Tobia Conforto wrote: (define-syntax test (syntax-rules () ((test (a ...) (b ...)) (quote ((a b) ...) 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. I beg to differ. This is a perfectly valid syntax-rule. The number of ellipses in the pattern doesn't need to match those in the template, not in this way. For example this is valid too--it does the opposite of test: (define-syntax untest (syntax-rules () ((untest (a b) ...) (quote ((a ...) (b ...)) (untest (1 10) (2 20) (3 30)) = ((1 2 3) (10 20 30)) 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. I think you are reading it wrong. Let's apply it to test: (define-syntax test (syntax-rules () ((test (a ...) (b ...)) (quote ((a b) ...) Pattern variables [for example, the 'b inside (b ...)] that occur in subpatterns [the same 'b is also the subpattern in this case] followed by one or more instances of the identifier ... [one instance] are allowed *only* in subtemplates [(a b) is the subtemplate] that are followed by as many instances of ... [again one instance.] Applied to untest: (define-syntax untest (syntax-rules () ((untest (a b) ...) (quote ((a ...) (b ...)) Pattern variables [for example, the 'a in (a b)] that occur in subpatterns [(a b) is the subpattern] followed by one or more instances of the identifier ... [one instance] are allowed *only* in subtemplates [the 'a inside (a ...) is the subtemplate] that are followed by as many instances of ... [again one instance.] AFAICS, the only possible error that can happen at macro expansion time, related to the ellipsis, is to take a macro combining several pattern-ellipses into one template-ellipsis (such as test above) and apply it to lists of different length. What I'm proposing is to always signal it as an error, not just half of the times. Tobia ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users