emacs-devel
[Top][All Lists]
Advanced

[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: Wed, 15 Nov 2023 01:07:27 +0000

On Wed, Nov 15, 2023 at 12:46 AM Dmitry Gutov <dmitry@gutov.dev> wrote:

> Then it must have a seq-do implementation that yields :secret-voodoo one
> or several times.

Not really.  Only if I use my seq in contexts where I need that
generic, and being second argument to seq-difference doesn't count.
So why should I bother implementing that when my code is working
fine today?

But say I did that seq-do, then what is the seq-contains-p generic good
for then?  Why some many redundant generics that the user learns the
hard way have to be consistent with each other?

> And then the seq-contains-pred implementation will do
> right by it (the default one, not the specialization for lists).
>
> >> This is not documented,
> >
> > You don't say? :-)  i think we should get started on documenting all
> > these ad-hoc rules (sorry but in this case they are quite literally
> > ad-hoc).  Better than nothing, I guess, since as to actually enforcing
> > them, I think that train has left the station a long time ago and is
> > now in a voodoo swamp in monkey island.
>
> Not sure "enforcing them" is the right phrase: I wonder if there's ever
> been a change proposed to seq.el which would break them.

I think it's pretty easy to do, especially if these optimziations
want going to go all the way to cl-lib's easier-to-get optimal
performance.  What about this?  Is this toy implementation of
compressed space-saving lists legal?

(cl-defmethod seq-do (function (l (head :m6-sparse)))
  (mapc (lambda (e)
          (if (eq e :double-o-seven)
              (progn (funcall function 0)
                     (funcall function 0)
                     (funcall function 7))
            (funcall function e)))
        (cdr l)))

(cl-defmethod seq-reverse ((l (head :m6-sparse)))
  (let (res)
    (seq-do (lambda (e) (push e res)) l)
    res))

(seq-difference '(:m6-sparse 1 2 :double-o-seven 4) '(7)) ;; => (1 2 0 0 4)

Again, not implementing all the generics, just the ones I need
to get my desired effect, which in this case is passing a
custom sequence type as a first argument to seq-difference.

João



reply via email to

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