help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: string-match bug?


From: Pascal J. Bourguignon
Subject: Re: string-match bug?
Date: Tue, 08 Dec 2009 22:23:27 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <mailman.12518.1260269458.2239.help-gnu-emacs@gnu.org>,
>  Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
>
>> Barry Margolin wrote:
>> > In article <mailman.12469.1260221021.2239.help-gnu-emacs@gnu.org>,
>> >  Matthew Dempsky <matthew@dempsky.org> wrote:
>> > 
>> >> On Mon, Dec 7, 2009 at 12:37 PM, Andreas Röhler
>> >> <andreas.roehler@easy-emacs.de> wrote:
>> >>> Why should questioned string respond here it contains an empty string at 
>> >>> position 0?
>> >>> Makes no sense for me.
>> >> Here's an analogy: (string-match "xyzzy" "fooxyzzybar") returns 3.
>> >> This is because the first 5 characters starting at position 3 are
>> >> "xyzzy", the same as the first string parameter.  The significance of
>> >> 5 here is the length of "xyzzy".
>> >>
>> >> Similarly, (string-match "" "foo") returns 0.  This is because the
>> >> first 0 characters starting at position are "", the same as the first
>> >> string parameter.
>> > 
>> > Here's another example of a limit case:
>> > 
>> > (string-match "a*" "b") returns 0, because a* matches zero or more a's, 
>> > and there are zero a's at position 0.
>> > 
>> 
>> Hmm, interesting
>> 
>> IMHO that differs:
>> 
>> (string-match "a*" "b") asks for a non-occurrence too. So "0" of first 
>> position is plausible.
>
> What's the difference between a non-occurrence and a zero-length 
> occurrence?
>
> The nice thing about regular expressions is that the following syllogism 
> holds:
>
> If 
> (string-match (concat regex1 regex2) (concat str1 str2))
> then
> (and (string-match regex1 str1) (string-match regex2 str2))
>
> You need the empty regex case to work for the limiting case of this.


(defun imply (a b) (or (not a)  b))

(let ((regex1 "a")
      (regex2 "b")
      (str1 "ab")
      (str2 "x"))

  (imply (string-match (concat regex1 regex2) (concat str1 str2))
         (and  (string-match  regex1 str1) (string-match  regex2 str2))))

--> nil


Perhaps you mean:

  (imply (and  (string-match  regex1 str1) (string-match  regex2 str2))
         (string-match (concat regex1 regex2) (concat str1 str2)))


-- 
__Pascal Bourguignon__


reply via email to

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