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: Thierry Volpiatto
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 09:52:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Bastien <address@hidden> writes:

> Dmitry Gutov <address@hidden> writes:
>
>> 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.
>>
>> FWIW, it's common behavior in many other programming languages.
>
> Which behavior?  The one I expect?
What about protecting your code like this?

(let ((str "abc")
      (ind 9999))
  (substring str 0 (min (length str) ind)))
=>"abc"

You will never have error:

(loop with str = "abcdef"
      for ind from 0 to 7
      do (princ (substring str 0 (min (length str) ind)))
      do (terpri))

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




reply via email to

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