[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's missing in ELisp that makes people want to use cl-lib?

From: João Távora
Subject: Re: What's missing in ELisp that makes people want to use cl-lib?
Date: Tue, 31 Oct 2023 10:38:09 +0000

On Tue, Oct 31, 2023 at 2:32 AM Adam Porter <adam@alphapapa.net> wrote:
> > Do people really want `cl-pushnew', with its keyword arguments?
> > Or would a simple `pushnew' be even more pleasing?
> It might be more aesthetically or ideologically pleasing, but it would
> be much less useful.  :test is often necessary for using EQUAL (as EQ is
> often the wrong function to use); without it, a hypothetical non-CL
> PUSHNEW function would often be unusable.  And :key makes it easy to use
> with, e.g. structs' accessor functions (which are very helpful for
> developers as they allow compile-time checking, completion, etc).
> When CL-PUSHNEW is called without keyword arguments, it's as simple as a
> hypothetical non-CL PUSHNEW that offered no keyword arguments.  The
> keyword arguments provide optional flexibility; without them, one would
> have to write a much larger, more complex form to do the same things.

Of course.

The other day I noticed we have a C function called 'car-less-than-car'
whose only point is to optimize a super-specific use of 'sort'.  Maybe
in 1993 we didn't have compiler macros but now we do, so this is the
wrong way to go about it.

We should just write

  (cl-sort foo #'< :key #'car)

which is much more modular, readable, reusable, and doesn't require
the programmer to know of this specific vocabulary.

Sure, "but what about the optimization?", I hear you ask.  Well if
you must have it then just use a compiler macro to have your cake and
eat it too.

In this case, something like

  (defun cl-sort-compiler-macro (form &rest args)
    (if (equal (cdr args) '(#'< :key #'car))
        `(cl-sort ,(car args) #'car-less-than-car)

and add it to the cl-sort declaration with

  (declare (compiler-macro 'cl-sort-compiler-macro))

> Finally, if there were an additional, non-CL PUSHNEW function added, I
> would think that would be much more confusing to users, especially new
> ones, for there to be a difference in behavior between PUSHNEW and

Exactly.  Please don't do this, we have enough such cases already.
Either migrate the fully functional version or don't.

Also, it's not too late to add keyword arguments to our 'sort'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]