[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
From: |
Bastien |
Subject: |
Re: Why (substring "abc" 0 4) does not return "abc" instead of an error? |
Date: |
Mon, 16 Jul 2012 09:14:00 +0200 |
User-agent: |
Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) |
Juanma Barranquero <address@hidden> writes:
> On Mon, Jul 16, 2012 at 1:59 AM, Bastien <address@hidden> 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
- Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/15
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Juanma Barranquero, 2012/07/15
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/15
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Juanma Barranquero, 2012/07/15
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?,
Bastien <=
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Stefan Monnier, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Tassilo Horn, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Lars Magne Ingebrigtsen, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Tassilo Horn, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Pascal J. Bourguignon, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/16
- Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?, Bastien, 2012/07/16