From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error? Date: Mon, 16 Jul 2012 02:10:37 +0200 Message-ID: References: <87fw8smxag.fsf@gnu.org> <877gu4mv85.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1342397486 25786 80.91.229.3 (16 Jul 2012 00:11:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 00:11:26 +0000 (UTC) Cc: emacs-devel@gnu.org To: Bastien Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 16 02:11:25 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 1SqYuK-00069k-Sk for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2012 02:11:25 +0200 Original-Received: from localhost ([::1]:46108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqYuK-0000d6-1W for ged-emacs-devel@m.gmane.org; Sun, 15 Jul 2012 20:11:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqYuG-0000d0-O2 for emacs-devel@gnu.org; Sun, 15 Jul 2012 20:11:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqYuF-0001A8-Rx for emacs-devel@gnu.org; Sun, 15 Jul 2012 20:11:20 -0400 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:35749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqYuE-00019r-CZ; Sun, 15 Jul 2012 20:11:18 -0400 Original-Received: by pbbrp2 with SMTP id rp2so10412445pbb.0 for ; Sun, 15 Jul 2012 17:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=DPPRQIYhugU7C8VieJgEBuzytKFt/hd3uzlbTnZwFqM=; b=XGDClFVUajfMsAjaT2V5HI5+Mm8Y2Jo6/jpw/SQ9gajhQkRGMmW8UdIkgpPIcg2r9D cARs4E7jsprsoHnce2PMoLDzZx1d/yCIT4eZOobuYEdlid9IzWkIUL9UxLsKm7IQ94Yu 98E3XWBoQrgyQyS0PWpKMMgGmhyIBNJMItR9DUK9nn4IUb2kaQuIzuy/CuDPrIjkeV9g ZXW+W5Nl50VL4FA0NiAItH182rmc3t8NOYpiVkWVulxcgue49rzc23bZkZWZdJA9qU0u vjStMha4pzBZFrZuJJukU0Tg3aNgmlSXO9s/IpNJPRsqb9fha38dck1R/S86Z1mKlVzU zE7g== Original-Received: by 10.68.201.7 with SMTP id jw7mr22295941pbc.60.1342397477478; Sun, 15 Jul 2012 17:11:17 -0700 (PDT) Original-Received: by 10.142.162.16 with HTTP; Sun, 15 Jul 2012 17:10:37 -0700 (PDT) In-Reply-To: <877gu4mv85.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.41 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:151647 Archived-At: 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. > 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. 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'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 Juanma