Re: Choose-Your-Own-Ellipsis Taylor Campbell 14 Oct 2003 21:33 UTC
On Monday, Oct 13, 2003, at 10:43 US/Eastern, Allophone Petrofsky wrote: > I don't know what the best exact syntax for this extension would be. > Here are several possibilities (using the conventions foo* == any > number of foo, and foo? == zero or one foo): > > -- Ellipsis choice before the literals, as above: > (syntax-rules <ellipsis>? <literals> <rule>*) > > -- After the literals: > (syntax-rules <literals> <ellipsis>? <rule>*) > > -- On a per-rule basis: > (syntax-rules literals (<ellipsis>? <pattern> <template>) ...) > > -- After the literals, with an extra "noise word" (like cond's =>) > to distinguish this from other syntax-rules extensions: > (syntax-rules <literals> (ellipsis <ellipsis>)? <rule>*) I like this idea most. This lets me do some other macrology that would have been rather irritating, because you no longer need to pass the 'free pattern variables' in submacros to avoid accidental ellipsis conflict. I'll modify the draft to define this, but we shall first to decide which of those four options to choose: opinions, anyone? (I don't care either way.) This _would_ also eliminate the issue of matching ellipsis literally but for one problem: we have no guards or non-linear patterns, so we can't do something like: (define-syntax contrived-example (syntax-rules () ((_ (syntax-rules ?ellipsis ?literals ;; ^^^^^^^^^ ((?ignored ?foo ?ellipsis) ?template))) ;; ^^^^^^^^^ (display "You've got ellipsis!")) ((_ ?foo) (display "No ellipsis yet.")))) and have (contrived-example (syntax-rules ::: () ((_ ?bar :::) baz))) expand to (display "You've got ellipsis!") Having mentioned non-linear patterns, what are some opinions on adding them, and what their specific semantics should be? If I do add non- linear patterns, should SYNTAX=? defined as (define-syntax syntax=? (syntax-rules () ((_ ?sk ?fk ?x ?x) ?sk) ((_ ?sk ?fk ?x ?y) ?fk))) compare identifiers boundly, freely, or symbolically? What are some thoughts on non-linear patterns and guards, or, if guards, how they might be best added to SYNTAX-RULES?