GNU bug report logs - #50704
Feature request: Add ensure-list in cl-lib

Previous Next

Package: emacs;

Reported by: Clément Pit-Claudel <cpitclaudel <at> gmail.com>

Date: Mon, 20 Sep 2021 19:44:01 UTC

Severity: wishlist

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50704 in the body.
You can then email your comments to 50704 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50704; Package emacs. (Mon, 20 Sep 2021 19:44:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Clément Pit-Claudel <cpitclaudel <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 20 Sep 2021 19:44:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: bug-gnu-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Feature request: Add ensure-list in cl-lib
Date: Mon, 20 Sep 2021 15:43:30 -0400
Hi all,

There are 40+ instances of the following code pattern in Emacs' code base, and many more in packages:

   (if (listp x) x (list x))

It's easy to find single-line instances of it using the regexp [(]if [(]listp .*[(]list .

This pattern is called "ensure-list" in CL:

  (defun ensure-list (thing)
    "Returns THING as a list.

  If THING is already a list (as per listp) it is returned,
  otherwise a one element list containing THING is returned."
    (if (listp thing)
        thing
        (list thing)))

I would like to add a similar function in Emacs, since it comes up so often.  Is that an acceptable change?  

If so:
- Which cl-*.el file should it go into, and where in that file?  
- Should it be a defun or a define-inline?  
- And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?  
- Finally, where should it be documented?

Cheers,
Clément.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50704; Package emacs. (Mon, 20 Sep 2021 21:07:01 GMT) Full text and rfc822 format available.

Message #8 received at 50704 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: 50704 <at> debbugs.gnu.org
Subject: Re: bug#50704: Feature request: Add ensure-list in cl-lib
Date: Mon, 20 Sep 2021 23:05:54 +0200
Clément Pit-Claudel <cpitclaudel <at> gmail.com> writes:

> I would like to add a similar function in Emacs, since it comes up so often.  Is that an acceptable change?  
>
> If so:
> - Which cl-*.el file should it go into, and where in that file?  

I don't think it has to be in cl at all -- we can just call it
`ensure-list'.

> - Should it be a defun or a define-inline?  
> - And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?  
> - Finally, where should it be documented?

defun, depends, and in the list section.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50704; Package emacs. (Tue, 21 Sep 2021 15:30:02 GMT) Full text and rfc822 format available.

Message #11 received at 50704 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 50704 <at> debbugs.gnu.org,
 Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Subject: Re: bug#50704: Feature request: Add ensure-list in cl-lib
Date: Tue, 21 Sep 2021 08:29:37 -0700
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> I don't think it has to be in cl at all -- we can just call it
> `ensure-list'.

+1

>> - And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?

To expand on what Lars said, they can (IMO should) be updated unless
they need to be compatible with old versions of Emacs.

(I would add a comment to the other instances along the lines of "change
to `ensure-list' once Emacs 27.1 compatibility is dropped".)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50704; Package emacs. (Tue, 21 Sep 2021 18:32:01 GMT) Full text and rfc822 format available.

Message #14 received at 50704 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 50704 <at> debbugs.gnu.org,
 Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Subject: Re: bug#50704: Feature request: Add ensure-list in cl-lib
Date: Tue, 21 Sep 2021 20:31:45 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

>> I don't think it has to be in cl at all -- we can just call it
>> `ensure-list'.
>
> +1

I've now added this to Emacs 28.  (And now I'm waiting for complaints
that we should name it `list-ensure' instead.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 50704 <at> debbugs.gnu.org and Clément Pit-Claudel <cpitclaudel <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 21 Sep 2021 18:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50704; Package emacs. (Tue, 21 Sep 2021 18:44:02 GMT) Full text and rfc822 format available.

Message #19 received at 50704 <at> debbugs.gnu.org (full text, mbox):

From: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>, Stefan Kangas <stefan <at> marxist.se>
Cc: 50704 <at> debbugs.gnu.org
Subject: Re: bug#50704: Feature request: Add ensure-list in cl-lib
Date: Tue, 21 Sep 2021 14:43:27 -0400
On 9/21/21 2:31 PM, Lars Ingebrigtsen wrote:
> Stefan Kangas <stefan <at> marxist.se> writes:
> 
>>> I don't think it has to be in cl at all -- we can just call it
>>> `ensure-list'.
>>
>> +1
> 
> I've now added this to Emacs 28.  (And now I'm waiting for complaints
> that we should name it `list-ensure' instead.)

Nice, thanks a lot!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 20 Oct 2021 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 160 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.