all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Bastien <bzg@gnu.org>
To: Juanma Barranquero <lekktu@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 09:14:00 +0200	[thread overview]
Message-ID: <871ukcmb47.fsf@gnu.org> (raw)
In-Reply-To: <CAAeL0STZCHYtchx4UG9fgTyrpcgPXFuVV=8mgFHzb0ntz3z74w@mail.gmail.com> (Juanma Barranquero's message of "Mon, 16 Jul 2012 02:10:37 +0200")

Juanma Barranquero <lekktu@gmail.com> writes:

> On Mon, Jul 16, 2012 at 1:59 AM, Bastien <bzg@gnu.org> wrote:
>
>> I read (substring "abc" 0 4) as "return the biggest substring
>> between 0 and 4" -- even if the string does not have 4 characters.
>
> "Even if the string does not have 4 characters" is not even suggested
> in substring's doc.

I know -- I was just expressing my spontaneous (and erroneous)
assumption.

>> Surely I misread, but this would be handy in some cases, instead
>> of using something like (format "%.4s" "abc").
>
> Would it be handy? Sometimes, perhaps. At other times, having
> substring check that TO is indeed in range is quite useful. 

I would be happy with a third optional argument FAIL-SILENTLY.

> Also, if
> you start with substring, then it will be buffer-substring, and then
> most functions that deal with string ranges, and then buffer ranges?

I get your point and I don't mind a bit of discipline.

Still, `substring' already behaves differently than its cousins
by allowing negative values as arguments.  I have a fuzzy feeling
my expectation comes from this peculiarity, but cannot formalize how

> I'm sure use cases could be found for all these functions where your
> expansive interpretation would be handy...
>
> BTW, for unexpected behavior wrt strings, my favourite is this one
> (it's not a bug);
>
> (let ((s "ab") (m 2)) (eq (substring s 0 m) (substring s 0 m))) => nil
> (let ((s "ab") (m 1)) (eq (substring s 0 m) (substring s 0 m))) => nil
> (let ((s "ab") (m 0)) (eq (substring s 0 m) (substring s 0 m))) => t

Well, this boils down to

(eq "a" "a") => nil
(eq "" "")   => t

where "" is really nil -- I my brain can swallow easily.

-- 
 Bastien



  reply	other threads:[~2012-07-16  7:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-15 23:15 Why (substring "abc" 0 4) does not return "abc" instead of an error? Bastien
2012-07-15 23:29 ` Juanma Barranquero
2012-07-15 23:59   ` Bastien
2012-07-16  0:10     ` Juanma Barranquero
2012-07-16  7:14       ` Bastien [this message]
2012-07-16 16:15         ` Stefan Monnier
2012-07-16 16:22           ` Bastien
2012-07-16 16:46           ` Bastien
2012-07-16 17:57             ` Tassilo Horn
2012-07-16 18:51               ` Lars Magne Ingebrigtsen
2012-07-16 19:30                 ` Bastien
2012-07-16 19:30                 ` Tassilo Horn
2012-07-16 20:20                 ` Pascal J. Bourguignon
2012-07-16 19:25               ` Bastien
2012-07-16 19:43                 ` Bastien
2012-07-16 20:19             ` Pascal J. Bourguignon
2012-07-16 20:30             ` Stefan Monnier
2012-07-16 22:28               ` Lennart Borgman
2012-07-16 22:48                 ` Bastien
2012-07-16 22:53                   ` Lennart Borgman
2012-07-16  7:38       ` Andreas Schwab
2012-07-16  9:40         ` Juanma Barranquero
  -- strict thread matches above, loose matches on Subject: below --
2012-07-16  3:45 Dmitry Gutov
2012-07-16  7:32 ` Bastien
2012-07-16  7:52   ` Thierry Volpiatto
2012-07-16  8:38     ` Bastien
2012-07-16 13:03   ` Dmitry Gutov
2012-07-16 14:32     ` Bastien
2012-07-16 13:10 ` Pascal J. Bourguignon
2012-07-16 14:40   ` Bastien
2012-07-16 15:00     ` Pascal J. Bourguignon
2012-07-16 15:07       ` Lennart Borgman
2012-07-16 15:19         ` Pascal J. Bourguignon
2012-07-16 15:22         ` Bastien
2012-07-16 15:46       ` Bastien
2012-07-16 15:49         ` Bastien
2012-07-16 19:49           ` Thien-Thi Nguyen
2012-07-16 22:32             ` Bastien
2012-07-16 15:56         ` Pascal J. Bourguignon
2012-07-16 16:13           ` Bastien
2012-07-16 19:00 Dmitry Gutov
2012-07-16 19:51 ` Tassilo Horn

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871ukcmb47.fsf@gnu.org \
    --to=bzg@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.