[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 00:53:09 +0000 |
On Tue, Nov 14, 2023 at 5:40 PM Tomas Hlavaty <tom@logand.com> wrote:
>
> On Tue 14 Nov 2023 at 11:47, João Távora <joaotavora@gmail.com> wrote:
> > On Tue, Nov 14, 2023 at 10:55 AM Po Lu <luangruo@yahoo.com> wrote:
> > LOOP, pcase, etc, like any other macros, are mini-languages. Like
> > any higher-level language, the more powerful they are, the more
> > transformations they will do on your input. LOOP is pretty powerful,
> > and may or may not be suitable for the task at hand, like any other
> > language.
>
> The question is if those are "nice" mini-languages or expressing the
> code in simple emacs-lisp is nicer.
>
> > At any rate Tomas' translation of the loop is just plain
> > wrong. Where is 'type-spec' being bound? It needs to be
> > destructured:
>
> Thanks, you found a bug in the sketch. It should have been:
>
> (puthash (pop f) (comp-type-spec-to-cstr (pop f)) h)
>
> or maybe
>
> (puthash (car f) (comp-type-spec-to-cstr (cadr f)) h)
Yeah, this one's better. The pop is just confusing. As is
the setq in the while condition, which my common lisp priests
would not approve. But the dolist+destructuring-bind is pretty
nice and solves all that.
> (dolist (x comp-known-type-specifiers)
> (destructuring-bind (f type-spec) x ...))
>
> if emacs-lisp had destructuring-bind.
But it does! in cl-lib.el no less :-)
> (let ((h (make-hash-table :test #'eq)))
> (dolist (x comp-known-type-specifiers h)
> (apply (lambda (f type-spec)
> (puthash f (comp-type-spec-to-cstr type-spec) h))
> x)))
>
This one is kinda hard to read for me, at least I couldn't tell
if it was correct right way, putting a lambda in there confuses
things (also if I not mistaken 'apply' instead of directly accessing
the elements is slower).
Anyway, I think
(cl-loop with h = (make-hash-table :test #'eq)
for (f type-spec) in comp-known-type-specifiers
do (puthash f (puthash f (comp-type-spec-to-cstr type-spec) h)
finally return h)
is the comparable loop and I don't think it's so bad.
It's one line less and less complex sexp tree.
But all your solutions are nice too, so I guess I'm pretty
tolerant. I don't know if I would write this loop myself
because while the destructuring is nice, the return h spoils
it, and the dolist gives you for free (if you know the
mini-language ;-) )
Loop is really good (IMHO!) for complex iteration with
repeat, counts, maximizations, early returns. I like loop's
self-documenting properties.
Complex iteration happens in programs, in all languages! Some
things are hard regardless of the idiom, unless you learn the
problem domain and the code is documented.
João
- Re: What's missing in ELisp that makes people want to use cl-lib?, (continued)
- Re: What's missing in ELisp that makes people want to use cl-lib?, João Távora, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?, Po Lu, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?, João Távora, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Eli Zaretskii, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, João Távora, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Eli Zaretskii, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Po Lu, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, João Távora, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Eli Zaretskii, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Tomas Hlavaty, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?,
João Távora <=
- Re: What's missing in ELisp that makes people want to use cl-lib?, Tomas Hlavaty, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?, Richard Stallman, 2023/11/20
- Re: What's missing in ELisp that makes people want to use cl-lib?, Sebastián Monía, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?, Eli Zaretskii, 2023/11/14
- Re: What's missing in ELisp that makes people want to use cl-lib?, Emanuel Berg, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, T.V Raman, 2023/11/15
- Re: What's missing in ELisp that makes people want to use cl-lib?, Michael Heerdegen, 2023/11/12
- RE: [External] : Re: What's missing in ELisp that makes people want to use cl-lib?, Drew Adams, 2023/11/12
- Re: [External] : Re: What's missing in ELisp that makes people want to use cl-lib?, João Távora, 2023/11/12
- RE: [External] : Re: What's missing in ELisp that makes people want to use cl-lib?, Drew Adams, 2023/11/12