> On Mar 27, 2018, at 4:01 PM, Justin Pombrio <justinlpomb...@gmail.com> wrote: > > I'm surprised by the behavior of using a pattern variable under one set of > ellipses in the pattern, and under two sets of ellipses in the template: > > #lang racket > > (require (for-syntax syntax/parse)) > > (define-syntax (test stx) > (syntax-parse stx > [(_ (x y ...) ...) #''(top (list (x y) ...) ...)])) > > (test (a 1 2 3) > (b 4 5 6) > (c 7 8 9)) >
Let’s agree that x stands for a, b, c and y stands for 1,2,3 and 4,5,6 and 7,8,9. So what does (x y) … mean: — iterate over both x and y, which yields (list (a 1) (b 3) (c 3)) — fix x and iterate over y, which would give you (list (a 1) (a 2) (a 3)) You need to make this choice independent of context once you have confirmed that there are “enough” ellipses. Once you have made the choice you can iterate over the “free” list and you get one of the two results. Why do you think that the law below wouldn’t hold in the presence of the chosen behavior? > I would expect this to produce: > > '(top (list (a 1) (a 2) (a 3)) > (list (b 4) (b 5) (b 6)) > (list (c 7) (c 8) (c 9))) > > But instead, it produces: > > '(top (list (a 1) (b 2) (c 3)) > (list (a 4) (b 5) (c 6)) > (list (a 7) (b 8) (c 9))) > > I'm surprised by this for two reasons: > - What I thought was the obvious implementation for matching/substituting > with ellipses produces the top answer. > - It breaks some properties that I would expect ellipses to have, such as: > > (define-syntax-rule (test (P ...)) (list Q ...)) > (test (T1 T2)) > === > (define-syntax-rule (test P P*) (list Q Q*)) > (test T1 T2) > > ; for all patterns P and templates Q and terms T1 and T2, where P* and Q* are > a renamed version of P and Q. > > Is this the expected behavior? And is there a good reason for it? > > Cheers, > Justin > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com > <mailto:racket-users+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.