[cduce-users] default match policy not working in sequences
Giuseppe Castagna
Giuseppe.Castagna at ens.fr
Wed Nov 3 23:19:59 CET 2004
Matthias Radestock wrote:
>>Anyway, we all agree the semantic for defaut value patterns in regexps
>> is problematic. I propose to use two different syntaxes for the two
>> semantics (consume an element or not). Actually, I propose to add
>> a "guard" construction /p in regexps; the pattern p must match
>> the tail of the sequence, and the regexp /p itself does not consume
>> anything.
>>
>>
>> So we can write:
>>
>> [ (A | /(x:=1)) B ] which accepts [ A? B ] and binds x->1 when A is
>> not matched.
>>
>> [ A /(x:=1) | B /(x:=2) ] which accepts [ A B ] and binds x->1 or x->2
>> according to the case.
>>
I guess here you want to say that it accepts [ A | B ]
>> [ (x:=1) /(y:=2) ] which accepts any sequence with one element
>>
>>
>> Comments on this proposal ?
>
I may be wrong but it seems to me that /p would be useful only for p a
default pattern. So why not adding special syntax just for it?
We could write
(x:=1) for the non consuming pattern
(x+=1) for the consuming one
and define (x?=1) as a shorthand for (x+=1)|(x:=1)
If we want to be more conservative we would probably set
(x-=1) for the non consuming pattern
(x:=1) for the consuming one
and define (x?=1) as a shorthand for (x:=1)|(x-=1)
furthermore this would avoid possible confusion with the expression e/t
(yes, one is an expression the other a pattern so no confusion should be
possible .. but ...).
The examples above would be rewritten as (below the second version):
[ (A | /(x:=1)) B ] -> [ (A | (x:=1)) B ]
-> [ (A | (x-=1)) B ]
[ A /(x:=1) | B /(x:=2) ] -> [ (A (x:=1)) | (B (x:=2)) ]
-> [ (A (x-=1)) | (B (x-=2)) ]
[ (x:=1) /(y:=2) ] -> [(x+=1) (y:=2)] (or all swaps of +/: x/y)
-> [(x:=1) (y-=2)]
Can you show me an exemple where /p with p not a default pattern would
be useful?
B.
More information about the Cduce-users
mailing list