[plt-scheme] Match bug
Bruce Hauman wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> I replied to this earlier, but my mailer has a bug and the message was
> not posted to the list. I think I lost several postings that way.
Thanks Bruce. I got your earlier message, but sent from Matthew. I
responded to him, so let me just cut and paste my message here.
>>And I was wondering if the grammar for match could be slightly extended.
>>
>>I believe that (and pat1 ... patn) could be (and lvp1 ... lvpn),
>>likewise for `or' and `not'.
>>
>>This would allow patterns such as
>>
>> (or ('p x) ...
>> ('q x) ...)
>
>
> Since you are only matching against one object here I am
> suprised that you would want to keep matching a pattern to it
> continually?
>
> Am I missing something?
>
> Have a good one,
> Bruce
I'm not sure I follow this question, so let me try to motivate my request...
If we were dealing with xml S-exprs, the pattern (or ('p x) ... ('q x)
...) would match a homogenous list of p or q elements binding the list
of contents to x.
Eg.
(match '((p "1") (p "2") (p "3"))
((or ('p x) ... ('q x) ...)
x)
(_ #f))
Would give ("1" "2" "3"). On the input '((q "8") (q "9")) it would give
("8" "9"). But for '((p "1") (q "9")) it would give #f, since the list
doesn't mind it's p's and q's.
This came up for me recently trying to write a structural checker for a
newsML document (an older draft of newsML). The DTD has something like
this:
<!ELEMENT newsitem (title+,
(newsitempart+ | newsobject | text )?,
metadata?,
handling*,
sourcedata?)>
I wanted to write:
(match-lambda
(('newsitem
('title _) ..1
(or
('newsitempart _) ..1
('newsobject _)
('text _))
<...>
)
#t))
It seems like the natural encoding, but this or pattern is not allowed
since ('newsitempart _) ..1 is not a pat but an lvp.
As far as I can see the above pattern can't be expressed in the current
grammar without nesting matches or other funkiness. I'd be happy to
hear I'm wrong. Also, changing the `and' `or' and `not' grammar
doesn't, as far as I can see, introduce any ambiguity.
-d