[Top][All Lists]

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

Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]

From: Philippe Vaucher
Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]
Date: Sun, 10 May 2020 00:01:30 +0200

> I understand, and I wasn't really expecting an example so soon, so
> thank you for taking the time to do it.  I was hoping for examples of
> the more complicated constructs, like the threading ones not the
> anaphoric variants.

I think I need your help here. About the threading ones, can you look
at the few examples at
https://github.com/magnars/dash.el#--x-optional-form-rest-more and
tell me what you need more?

The threading macros are useful when you'll "cascade" arguments into a
bunch of function. See it as a better and more flexible `let*`, for

(let* ((lst '(1 2 3))
         (lst-square (-map 'square lst))
         (lst-square-reverse (-reverse lst-square)))
  (pp lst-square-reverse))

>    (let ((lst '(1 2 3 4)))
>      (pp (--map-when (= it 2) 17 lst))
>      (pp (mapcar (lambda (it) (if (= it 2) 17 it)) lst)))
>    The point here is that the first one almost reads like english. The
>    intention is very clear (to me). The "pure lisp" one I have to put
>    more attention to it. I guess you'll disagree :-)
> I guess it is because you are more used to the abstraction level.  I
> find the later to be much more natural to write.  It also lends it
> self much easier (I think) if you wish to modify it at some later
> point, e.g., you put the lambda in a function.

Yes, it's hard ot make this example shine because it's too simple. It
was probably a poor example to begin with, still my point was that
"(map-when pred rep list)" speaks more to me than "use mapcar and pass
a lambda containing an if to it". Just by seeing the signature I know
what to do.

> I do not see what is won here won in this case, you write code only
> once -- you read it much more.  If the lambda does something remotley
> complicated, you would want to put it in a seperate function (either
> defun, or flet).

Well it's more of an example for the countless times you do simple
things in this lambda.

> This leads to easier testing and experimenting/debugging too, since in
> both cases (lambda or named function) you can use it as a normal form.
> That isn't true for the first example.

Agreed for complicated lambdas.

>    (let ((lst '("1" 2 "3" 4))
>          (delme (make-symbol "delme")))
>      (pp (--remove (and (numberp it) (= it 2)) lst))
>      (pp (delete delme (mapcar (lambda (it) (if (and (numberp it) (= it
>    2)) delme it)) lst))))
>    Yes, I now I can use cl-remove-if or seq-remove, but I think it
>    further illustrates the point: I see both seq- and cl- as attempts at
>    fixing the Emacs api that was lacking. If I'm not mistaken seq.el was
>    even inspired by dash.
> Why even do that! You could just use `delq`:
>    (delq 2 '("1" 2 "3" 4))

What if the list contains elements not comparable with `eq` or `=` ?
I'll show you the source of `seq-filter` as a reminder:

(cl-defgeneric seq-filter (pred sequence)
  "Return a list of all the elements for which (PRED element) is
non-nil in SEQUENCE."
  (let ((exclude (make-symbol "exclude")))
    (delq exclude (seq-map (lambda (elt)
                             (if (funcall pred elt)

> The more I think about it, it seems that people aren't looking to
>  learn Emacs Lisp -- but rather they want to learn
>  Haskell/Clojure/...?
>    In many languages, "flatten" is a basic concept. You'd expect
>    something as basic to be in the language...
> flatten-list?

Nice. Why isn't this function findable using `C-h f` in Emacs 26.3? I
tested with emacs -Q, and I even tried to load `subr` and `subr-x`.

Anway, I hope you understand now that the point is not that Emacs
doesn't have such functions, is that there's no centralized place
where you have the exact short list of functions related to a topic.
Using prefixes like in dash or s.el allows for easy discoverability
using `C-h f`.

We'd be getting close to it by writing some mode that parses
and grep for `-- function` and list these in a grouped manner like
dash/s.el does. I might get around to start doing this if time allows.

reply via email to

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