Hi, [Re-adding Cc: guile-de...@gnu.org.]
Alex Shinn <alexsh...@gmail.com> writes: > On Mon, Sep 6, 2010 at 12:04 AM, Ludovic Courtès <l...@gnu.org> wrote: >> >> GNU Guile 1.9 now uses your implementation of ‘match’ as a nice >> replacement for Wright’s implementation, so thank you! >> >> I stumbled upon this incompatibility: Wright’s ‘match’ supports ‘..1’, >> ‘..2’, etc., which mean “1 or more”, “2 or more”, etc., and the >> associated variable (when there’s one) is bound to the list that >> matches: >> >> (match '(a 1 2) (('a x ..1) x)) >> => (1 2) >> >> AFAICS these patterns aren’t implemented in your ‘match’. >> >> Do you have plans to implement them? > > Yes, these can't be implemented in syntax-rules. Well, since there are only 9 of them, they could probably be implemented as special cases, with an augmented ‘match-gen-ellipses’, which would be told the minimum number of elements expected? > It would be straightforward to implement an alternate > syntax such as > > (match '(a 1 2) (('a x .. 1) x)) > > or generalize it to > > (match '(a 1 2) (('a x <M> .. <N>) x)) > > where the <N> could be #f or left out to mean infinity, > which would be strictly more powerful than Wright's > syntax. Yes, this would be nice, too. > The main reason I haven't bothered adding this is > I've never needed it, and was waiting to hear reports > from people who do. > > Do you have any code which actually uses the ..k > patterns? :) I do! :-) http://git.sv.gnu.org/cgit/guile-rpc.git/tree/modules/rpc/compiler.scm#n312 Well it uses only ‘..1’. The same code would work with ‘..1’ replaced by ‘...’, but then errors in the input wouldn’t be detected as nicely. Thanks, Ludo’.