From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien 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:14:00 +0200 Organization: GNU Message-ID: <871ukcmb47.fsf@gnu.org> References: <87fw8smxag.fsf@gnu.org> <877gu4mv85.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342422824 13394 80.91.229.3 (16 Jul 2012 07:13:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2012 07:13:44 +0000 (UTC) Cc: emacs-devel@gnu.org To: Juanma Barranquero Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 16 09:13:44 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 1SqfV1-0004k1-2B for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2012 09:13:43 +0200 Original-Received: from localhost ([::1]:34466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqfUz-0001PZ-S0 for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2012 03:13:41 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqfUs-0001P8-J8 for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:13:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqfUm-0004Qq-KL for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:13:34 -0400 Original-Received: from mail-wg0-f49.google.com ([74.125.82.49]:55407) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqfUm-0004Qh-DO for emacs-devel@gnu.org; Mon, 16 Jul 2012 03:13:28 -0400 Original-Received: by wgbez12 with SMTP id ez12so3377746wgb.30 for ; Mon, 16 Jul 2012 00:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:date:message-id:mime-version:content-type; bh=M1PVYRFtXsQ+y0x5nCSq/QhCqIosy1QpxFcBpYfkPeQ=; b=O521owIR6VOu5zdPM7rvfYMQz6VlWSsi5NtlrTMQxVygMJ+f8OTo/T4HDZtNQnDfd8 3vZ7D4t5+Fbio8nWqk5NOqr9eZnYHQLWSC79v+zki/bAFQV63C2fcX3d2QuDyVTjSNdV awRtmq+5u4lr6IR1Dog0lpHQG70vbwHGVCAdokGBYfld6ntY67F0ylbkFC+q4eum8gLt RSZja551AInywOZPGKpIbM1PG5UlVcSpkGB+yyB8cZuwfilMprfISDstYG0BYWiQbIeW /XTvKX9pHcbpsbz7dosMspGSWAx0jOtSOsPc2utcJFxqomaFF4agfc/ncZfdNeuPl7uj vqDg== Original-Received: by 10.180.105.6 with SMTP id gi6mr15842222wib.4.1342422807485; Mon, 16 Jul 2012 00:13:27 -0700 (PDT) Original-Received: from myhost.localdomain (mar75-2-81-56-68-112.fbx.proxad.net. [81.56.68.112]) by mx.google.com with ESMTPS id fu3sm29755346wib.10.2012.07.16.00.13.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 00:13:26 -0700 (PDT) Original-Received: by myhost.localdomain (Postfix, from userid 1000) id EAF4F8207; Mon, 16 Jul 2012 09:14:00 +0200 (CEST) In-Reply-To: (Juanma Barranquero's message of "Mon, 16 Jul 2012 02:10:37 +0200") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.49 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:151653 Archived-At: 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. 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