guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ‘match’ and “k or more” patterns


From: Ludovic Courtès
Subject: Re: ‘match’ and “k or more” patterns
Date: Wed, 08 Sep 2010 14:06:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi,

Alex Shinn <address@hidden> writes:

> On Mon, Sep 6, 2010 at 9:12 PM, Ludovic Courtès <address@hidden> wrote:
>>
>> 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?
>
> Oh, the Wright syntax limited you to 9 forms, so "..10" is illegal?

>From Wright’s 1995 paper & doc I thought k > 9 wasn’t supported but
apparently it is:

--8<---------------cut here---------------start------------->8---
guile> (use-modules (ice-9 match)) ;; <- Wright’s code
guile> (match (iota 30) ((a ..10) a))
$1 = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
28 29)
guile> (match (iota 30) ((a ..22) a))
$2 = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
28 29)
guile> (version)
$3 = "1.8.7"
--8<---------------cut here---------------end--------------->8---

:-(

> "..1" is actually useful - it's the analog of "+" in regular
> expressions, and allows simplifying many syntax-rules
> patterns you see written (elt0 elt1 ...) as (elt ..1).  If
> the elements are more complex patterns this is a big
> win.

Agreed.

So perhaps one solution would be to:

  1. Have a special case for ‘..1’, since it’s quite handy.

  2. Have a new syntax form, like ‘.. k’, as you suggested.

What do you think?

Thanks,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]