[cduce-users] default match policy not working in sequences
matthias at sorted.org
Wed Nov 3 22:17:38 CET 2004
Alain Frisch wrote:
> Matthias Radestock wrote:
>> ((<next-date>[(date::Char* 'UTC' Char*)]) | (date := "Unknown"))
> >which I had expected to match sequences with or without a valid
> next-date element, returning a date value of "Unknown" in the latter case.
> How could this be ? Without the specific semantics for default value
> patterns in regexp, the (date := "Unknown") would always match an
> element, even if there is not <next-date> element at all.
You are, of course, correct.
> What's wrong with
> (<next-date>([date::Char* 'UTC' Char*] | (date := "Unknown"))
> |(date := "Unknown"))
I can confirm that this works. Thanks.
> 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
> 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.
> [ (x:=1) /(y:=2) ] which accepts any sequence with one element
> Comments on this proposal ?
I like it.
More information about the Cduce-users