emacs-devel
[Top][All Lists]
Advanced

[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: Sat, 9 May 2020 17:30:45 +0200

> Can you give some examples of using dash.el?

Let's start with a disclaimer: it's hard to come with examples on the
spot. Also because I usually code with dash or seq it's hard for me to
know the real "plain emacs lisp" equivalent.

(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 :-)

(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.

I was going to make an example with `-flatten` but I think this page
is better showing my point:
https://stackoverflow.com/questions/969067/name-of-this-function-in-built-in-emacs-lisp-library

In many languages, "flatten" is a basic concept. You'd expect
something as basic to be in the language... for me dash adresses these
"basics" you can't find easily in the manual. Same for other topics
(e.g set union/intersection/different), basically any topic related to
lists I can look on https://github.com/magnars/dash.el and quickly be
productive.

Now that I said all this, FWIW I'd agree that because there is seq-
and map- we don't really need dash- anymore in Emacs core for a lot of
use cases. Maybe the anaphoric/threading functions would be nice but I
doubt they'd interest you. Examples of threading:

(->> '(1 2 3) (-map 'square) (-remove 'even?)) ;; => '(1 9)
(--> "def" (concat "abc" it "ghi") (upcase it)) ;; => "ABCDEFGHI"



reply via email to

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