From: tomas@tuxteam.de
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: string-match bug?
Date: Wed, 9 Dec 2009 19:11:57 +0100 [thread overview]
Message-ID: <20091209181157.GA17507@tomas> (raw)
In-Reply-To: <4B1FDF51.1010002@easy-emacs.de>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Dec 09, 2009 at 06:33:05PM +0100, Andreas Röhler wrote:
> Juanma Barranquero wrote:
> > On Wed, Dec 9, 2009 at 09:05, Andreas Röhler
> > <andreas.roehler@easy-emacs.de> wrote:
> >
> >> Nonetheless, returning NIL at the second question looks like a more useful result -
> >
> > Why?
> >
> >> because taking incertitude.
> >
> > Which incertitude? Matching the empty regexp against any string is
> > always going to match.
>
> But simply by convention, isn't it?
>
> Aren't
>
> (string-match "" "a")
>
> and
>
> (string-match "" "")
>
> different cases in some perspective?
>
> The return value is censured being a position.
> Second case is plausible, there is an empty string at pos 0.
>
> First has no empty string at pos 0.
Of course it has don't you see it, very little there, between the " and
the a? There is another one at the end, right there between the a an the
". ;-)
Humour aside -- it makes things square up better. If you consider the
operation of "string concatenation", there is a "neutral element" (that
is the empty string). Thus "" + "foo" => "foo". So you can assume the
empty string to be everywhere within a string (or to be a substring of
every string at each position). Watch this:
(substring "yowza!" 2 4) => "wz"
(substring "yowza!" 2 2) => ""
So, "" is a substring of the string "yowza! at position 2 (it just
happens to have the length 0).
> Result is logically not plausible for me - even if I'm well able to live with... :)
It isn't logical. It's just a convention (but the one convention which
happens to make things easiest in the end). You can see a simiilar
convention in maths: in set theory, the empty set is considered to be a
subset of every set. Of course you might redefine all set operators
(inclusion, intersection, etc.) to exclude the empty set, but you would
just end up with tons of special cases for no gain. Same here (you'd
need, e.g. to special-case the substring function when END == START, but
what for?).
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFLH+htBcgs9XrR2kYRAjuSAJ9gxEnrgiR8Rrl2GO9uYb7t6tbnkwCfc2MC
7QJcRIjEt9yTpSxPRdU+BNs=
=FZ4V
-----END PGP SIGNATURE-----
next prev parent reply other threads:[~2009-12-09 18:11 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.12437.1260197731.2239.help-gnu-emacs@gnu.org>
2009-12-07 15:08 ` string-match bug? Colin S. Miller
2009-12-07 15:25 ` Colin S. Miller
2009-12-07 20:37 ` Andreas Röhler
2009-12-07 21:23 ` Matthew Dempsky
2009-12-08 10:42 ` Andreas Röhler
2009-12-08 11:35 ` Juanma Barranquero
2009-12-08 11:50 ` Peter Münster
[not found] ` <mailman.12522.1260273034.2239.help-gnu-emacs@gnu.org>
2009-12-08 15:56 ` Stefan Monnier
[not found] ` <mailman.12517.1260268988.2239.help-gnu-emacs@gnu.org>
2009-12-14 13:53 ` David Kastrup
[not found] ` <mailman.12469.1260221021.2239.help-gnu-emacs@gnu.org>
2009-12-08 3:22 ` Barry Margolin
2009-12-08 10:50 ` Andreas Röhler
2009-12-08 11:31 ` Peter Dyballa
2009-12-08 13:55 ` Andreas Röhler
[not found] ` <mailman.12518.1260269458.2239.help-gnu-emacs@gnu.org>
2009-12-08 20:48 ` Barry Margolin
2009-12-08 21:23 ` Pascal J. Bourguignon
2009-12-09 16:16 ` Stefan Monnier
2009-12-08 23:48 ` Matthew Dempsky
2009-12-09 8:05 ` Andreas Röhler
2009-12-09 12:56 ` Juanma Barranquero
2009-12-09 17:33 ` Andreas Röhler
2009-12-09 18:07 ` Matthew Dempsky
2009-12-09 18:13 ` tomas
2009-12-09 18:59 ` Andreas Röhler
2009-12-09 21:15 ` Matthew Dempsky
[not found] ` <mailman.12615.1260385212.2239.help-gnu-emacs@gnu.org>
2009-12-10 0:22 ` Barry Margolin
2009-12-09 18:11 ` tomas [this message]
2009-12-10 3:05 ` Kevin Rodgers
[not found] ` <mailman.12630.1260414617.2239.help-gnu-emacs@gnu.org>
2009-12-10 5:34 ` Stefan Monnier
2009-12-10 10:01 ` tomas
2009-12-10 11:00 ` Andreas Politz
2009-12-11 4:37 ` Kevin Rodgers
[not found] ` <mailman.12651.1260442881.2239.help-gnu-emacs@gnu.org>
2009-12-14 13:59 ` David Kastrup
[not found] ` <mailman.12606.1260380004.2239.help-gnu-emacs@gnu.org>
2009-12-09 19:08 ` Frank Fredstone
2009-12-10 19:25 ` Andreas Röhler
2009-12-10 23:41 ` Juanma Barranquero
[not found] ` <mailman.12689.1260473128.2239.help-gnu-emacs@gnu.org>
2009-12-10 20:40 ` Frank Fredstone
2009-12-09 21:33 ` Stefan Monnier
2009-12-10 6:38 ` Andreas Röhler
2009-12-14 13:51 ` David Kastrup
2009-12-07 14:55 Andreas Roehler
2009-12-07 15:31 ` Pierre Lorenzon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091209181157.GA17507@tomas \
--to=tomas@tuxteam.de \
--cc=andreas.roehler@easy-emacs.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).