emacs-devel
[Top][All Lists]
Advanced

[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 01:59:38 +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:15 AM, Bastien <address@hidden> wrote:
>
>> As the subject says: I wonder why
>>
>>   (substring "abc" 0 4)
>>
>> does not return "abc".
>
> Why should it? How it is different from (aref "abc" 4)?

I read (aref "abc" 4) as "return the 5th element of "abc"". 

So I expect an error here.

I read (substring "abc" 0 4) as "return the biggest substring
between 0 and 4" -- even if the string does not have 4 characters.

Surely I misread, but this would be handy in some cases, instead
of using something like (format "%.4s" "abc").

-- 
 Bastien



reply via email to

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