From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Alfred M. Szmidt" Newsgroups: gmane.emacs.devel Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs] Date: Sat, 09 May 2020 19:21:18 -0400 Message-ID: References: <0c88192c-3c33-46ed-95cb-b4c6928016e3@default> <87wo5mc04t.fsf@fastmail.fm> Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="59086"; mail-complaints-to="usenet@ciao.gmane.io" Cc: joostkremers@fastmail.fm, rms@gnu.org, emacs-devel@gnu.org To: Philippe Vaucher Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 10 01:21:57 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jXYn6-000FE1-PW for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 01:21:56 +0200 Original-Received: from localhost ([::1]:43674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXYn5-0002Wb-Ph for ged-emacs-devel@m.gmane-mx.org; Sat, 09 May 2020 19:21:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXYmW-0001Nd-QS for emacs-devel@gnu.org; Sat, 09 May 2020 19:21:20 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:33982) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXYmW-0006Fg-AJ; Sat, 09 May 2020 19:21:20 -0400 Original-Received: from ams by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1jXYmU-00086m-MX; Sat, 09 May 2020 19:21:18 -0400 In-Reply-To: (message from Philippe Vaucher on Sun, 10 May 2020 00:01:30 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249598 Archived-At: > 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? They are very trivial examples, they don't really show how people use it in actual code which is I think where we could have an interesting comparison. I'd like to see something more "real world" -- something that would be hard, or annoying to do in Emacs Lisp. (-> '(2 3 5)) ;; => '(2 3 5) '(2 3 5) (-> '(2 3 5) (append '(8 13))) ;; => '(2 3 5 8 13) (append '(2 3 5) '(8 13)) (-> '(2 3 5) (append '(8 13)) (-slice 1 -1)) ;; => '(3 5 8) (subseq (append '(2 3 5) '(8 13)) 1 -1) 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 example: (let* ((lst '(1 2 3)) (lst-square (-map 'square lst)) (lst-square-reverse (-reverse lst-square))) (pp lst-square-reverse)) Why even use let*? (-reverse (-map 'square '(1 2 3))) In these cases, I see absolutley no benefit of using ->, it just makes it more "magical" for no particular reason. And you can individually extract a form (which is useful when debugging), and it will have some meaning, take (-slice 1 -1). The function is described as (-slice LIST FROM &optional TO STEP) .. but 1 isn't a list! > 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. Polish speaks more to me than English, we all have our preferences and have to adjust when we speak or write in a different language. Which is why it is important to see things through the intended lense -- in this case, Emacs Lisp. Your example of using -slice instead of subseq is one such example -- I cannot assume that the word miasto will exist in English and mean city. > 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 `=` ? Everything is comparable using eq; but if you wish to strings content or fixnums specifically then remove-if would be a better choice with the correct predicate.. > 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`. It was added in 27.1. 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. That is the purpose of the Emacs Lisp manual. Using prefixes like in dash or s.el allows for easy discoverability using `C-h f`. Prefixes can help in that, sometimes but not always, since sometimes another prefix might make more sense. But neither `-' nor `s' is a good prefix for discoverability. We'd be getting close to it by writing some mode that parses https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html 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. That would be great!