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: Dmitry Gutov
Subject: Re: What's missing in ELisp that makes people want to use cl-lib?
Date: Wed, 15 Nov 2023 03:28:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 15/11/2023 03:07, João Távora wrote:
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?

Commentary at the top of seq.el says:

;; seq.el can be extended to support new type of sequences.  Here are
;; the generic functions that must be implemented by new seq types:
;; - `seq-elt'
;; - `seq-length'
;; - `seq-do'
;; - `seqp'
;; - `seq-subseq'
;; - `seq-into-sequence'
;; - `seq-copy'
;; - `seq-into'

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?

So any new type gets a lot of functions implemented very easily, and could add specialized implementations for performance.

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.

Very clever. I'm not thinking too well this time of night, but the first part of the reply in this email probably answers the question (there is a certain set of generics that must be implemeneted).



reply via email to

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