[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: Eli Zaretskii
Subject: Re: What's missing in ELisp that makes people want to use cl-lib?
Date: Sun, 12 Nov 2023 08:45:06 +0200

> From: Richard Stallman <rms@gnu.org>
> Cc: emacs-devel@gnu.org
> Date: Sat, 11 Nov 2023 21:57:02 -0500
>   > But when you need to process plists, for example, it becomes
>   > very handy.  This construct, which does require knowing a bit
>   > of the mini-language that is cl-loop,
>   >   (cl-loop for (k v) on plist by #'cddr collect (cons k v))
> It is certainly concise.  If I saw that code I would not understand it,
> but if you said what job it does I could see how it might do that.
> That's because cl-loop defines its own little language, which I don't know.

Btw, the above is a very simple use of cl-loop.  We have quite a few
of much more complex ones.  For example:

   with comp-ctxt = (make-comp-cstr-ctxt)
   with h = (make-hash-table :test #'eq)
   for (f type-spec) in comp-known-type-specifiers
   for cstr = (comp-type-spec-to-cstr type-spec)
   do (puthash f cstr h)
   finally return h)

or this:

            (cl-loop for i = 0 then (+ i (if (eq (nth i list) ?\\) 4 1))
                     for var = (nth i list)
                     while (< i size)
                     if (eq var ?\\)
                     collect (string-to-number
                              (concat (cl-subseq list (+ i 1) (+ i 4))) 8)
                     collect var))

or this:

   named loop
   with above
   for lane in (comp-cstr-ctxt-typeof-types comp-ctxt)
   do (let ((x (memq type lane)))
         ((null x) nil)
         ((eq x lane) (cl-return-from loop x)) ;A base type: easy case.
         (t (setq above
                  (if above (comp--intersection x above) x)))))
   finally return above))

It isn't an accident that the reference documentation of cl-loop in
cl.info takes a whopping 700(!) lines.

reply via email to

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