From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Colin Woodbury" Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension` Date: Wed, 26 May 2021 09:31:38 -0700 Message-ID: <9a92de1b-e313-468d-aa1f-7f969ed73688@www.fastmail.com> References: <6ff4b7d7-03ac-48d1-8d49-de66431d4e5b@www.fastmail.com> <87lf82y9pv.fsf@tcd.ie> <3780a7f9-19f4-4216-baa9-ce00b3dbace9@www.fastmail.com> <6ba4668c-9b39-40e0-a155-f7e583fd33b6@www.fastmail.com> <87czteeyoc.fsf@igel.home> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=772493e3add64f33b5e31f0aae586468 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31269"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Cc: emacs-devel@gnu.org To: "Andreas Schwab" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 26 18:33:00 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llwSo-0007qN-Cd for ged-emacs-devel@m.gmane-mx.org; Wed, 26 May 2021 18:32:58 +0200 Original-Received: from localhost ([::1]:55126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llwSn-0003KP-Ef for ged-emacs-devel@m.gmane-mx.org; Wed, 26 May 2021 12:32:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llwRy-0002eO-4g for emacs-devel@gnu.org; Wed, 26 May 2021 12:32:06 -0400 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:32909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llwRw-0006eq-4Q for emacs-devel@gnu.org; Wed, 26 May 2021 12:32:05 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 75C24FAD; Wed, 26 May 2021 12:32:01 -0400 (EDT) Original-Received: from imap1 ([10.202.2.51]) by compute1.internal (MEProxy); Wed, 26 May 2021 12:32:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fosskers.ca; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type; s=fm1; bh=ARQj5G1rgSabyssFnfWZ8A8UJaHQNkb Pld5Q/DtdUYQ=; b=eKF/Q46GEjnXpiiXzhWn6ioO3S0whnx2Q+NbzY5QZOsmAxt xHjFLgEBTeKz05gjigxcbo1/vD0Ypk5rkS5GZ0BBINk9DR//Vd9X1ysMMfvWj0zj E9xbOQf+Cp1aYTSfeLnMo5Rx2l6KrTKIATr8EECTC/zCoI1BmjiCFru2bfXPa3uj PKVB0v6NRqeYFfyLNoVFkN9/nmmWeGIyuzfFEg5VzpGPp2vSBG2utHG1a8F+vONa mRZ7sGwdX/IOXvfYJIEjWVnSZ9CElLBk7fL0lQsmouhFjf45qLs9niF0dcY2OhRP jPGXBcQ5qVjTTkqL88YAQ98AC52CQCwfWKysixQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=ARQj5G 1rgSabyssFnfWZ8A8UJaHQNkbPld5Q/DtdUYQ=; b=GqToedrjsm+aPfNN+c1hKb mhuxvFdiycSAmOh44mnOpYKJ5n5POjpqi39q7ajAI/VTHmpBCG5UP7QzY886uohe t93uI82BKAjowYAJcHuIjAdGWPO9FZ9d6O1yT8/AP73bX8+EAPhNIqS1GD7djyO8 MXqavSZXZe3rL0GGfcXhxg9ghLMkPjAeN04zGsW9CM05F86/uM/E2CpDhPjHBzF/ 3fY1Qpav7NswBi6D8XiD6yQcq9B6xiYrCXIU/LKecHZgPUjZ6IXAaKLy7E/zRiLs oEzHpxojlUANuEc22PocR47qImZB/pm14EcE0VGD1pRuiPf0BD+frs3s34PZ/7Gg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdekfedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsegrtderreerredtnecuhfhrohhmpedfveho lhhinhcuhghoohgusghurhihfdcuoegtohhlihhnsehfohhsshhkvghrshdrtggrqeenuc ggtffrrghtthgvrhhnpeefhfdvgedtueejffdtiefgheeugedvhfegueevuedtleevgeel geevfeffudejffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegtohhlihhnsehfohhsshhkvghrshdrtggr X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9A850130005F; Wed, 26 May 2021 12:32:00 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: <87czteeyoc.fsf@igel.home> Received-SPF: none client-ip=64.147.123.21; envelope-from=colin@fosskers.ca; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269918 Archived-At: --772493e3add64f33b5e31f0aae586468 Content-Type: text/plain Hi Andreas, In this particular case, the `string-trim-*` family of functions panic with the rather unhelpful `Wrong type argument: stringp, nil` message when passed `nil`, so the initial `when` is guarding against that. Since `nil` exists as a "bottom" value to every type in Elisp (not unlike C's null pointers), we adopt the C approach of "don't trust what we're given, and expect the user to check what they're returned". Such scenarios are precisely what macros like `when-let` are for, as far as I can tell. In general this approach is founded upon the ideas that: 1. `nil` is a good general signal for logical failure (for languages that lack generics, etc.). 2. Library code shouldn't crash/panic (but user code should feel free to). 3. It's okay to return `nil` if the docstrings are clear about when that happens. Please let me know if I've overlooked something, I'm happy to revise the patch. Cheers, Colin On Wed, 26 May 2021, at 00:34, Andreas Schwab wrote: > On Mai 25 2021, Colin Woodbury wrote: > > > +Returns nil if either of the FILENAME or EXTENSION are nil before > > +dot consolidation, or empty afterwards." > > + (when (and filename extension) > > I still don't see any reason to allow nil. A file name is always a > string. > > Andreas. > > -- > Andreas Schwab, schwab@linux-m68k.org > GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 > "And now for something completely different." > --772493e3add64f33b5e31f0aae586468 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
Hi Andreas,
=

In this particular case, the `string-trim-*` f= amily of functions panic with the rather unhelpful `Wrong type argument:= stringp, nil` message when passed `nil`, so the initial `when` is guard= ing against that. Since `nil` exists as a "bottom" value to every type i= n Elisp (not unlike C's null pointers), we adopt the C approach of "don'= t trust what we're given, and expect the user to check what they're retu= rned". Such scenarios are precisely what macros like `when-let` are for,= as far as I can tell.

In general this appr= oach is founded upon the ideas that:

1. `ni= l` is a good general signal for logical failure (for languages that lack= generics, etc.).
2. Library code shouldn't crash/panic (b= ut user code should feel free to).
3. It's okay to return = `nil` if the docstrings are clear about when that happens.

Please let me know if I've overlooked something, I'm hap= py to revise the patch.

Cheers,
Colin

On Wed, 26 May 2021, at 00:34, And= reas Schwab wrote:
On Mai 25 2021, Colin Woodbury wrote:

> +Returns nil if either of the FILENAME or EXTENSION are nil befo= re
> +dot consolidation, or empty afterwards."
> +  (when (and filename extension)

I still don't see any reason to allow nil.  A file name is a= lways a
string.

Andreas.
<= /div>

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint =3D 7578 EB47 D4E5 4D69 2510  2552 DF73= E780 A9DA AEC1
"And now for something completely differen= t."


--772493e3add64f33b5e31f0aae586468--