From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error? Date: Mon, 16 Jul 2012 09:52:13 +0200 Message-ID: <87y5mknnwy.fsf@gmail.com> References: <50038E42.1030508@yandex.ru> <87sjcskvow.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342425161 30020 80.91.229.3 (16 Jul 2012 07:52:41 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 07:52:41 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 16 09:52:41 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sqg6h-0005ao-1A for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2012 09:52:39 +0200 Original-Received: from localhost ([::1]:45804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqg6g-0000qQ-Dp for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2012 03:52:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqg6a-0000qJ-Uj for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:52:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sqg6Z-0007mt-Vm for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:52:32 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:44769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sqg6Z-0007mU-PM for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:52:31 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Sqg6W-0005Oh-5h for emacs-devel@gnu.org; Mon, 16 Jul 2012 09:52:28 +0200 Original-Received: from lbe83-2-78-243-104-167.fbx.proxad.net ([78.243.104.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 16 Jul 2012 09:52:28 +0200 Original-Received: from thierry.volpiatto by lbe83-2-78-243-104-167.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 16 Jul 2012 09:52:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: lbe83-2-78-243-104-167.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) Cancel-Lock: sha1:ICOEro5YI+kFO9kYjIDyVaptjqI= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151656 Archived-At: Bastien writes: > Dmitry Gutov writes: > >> Juanma Barranquero writes: >> >>> On Mon, Jul 16, 2012 at 1:59 AM, Bastien 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