From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Philippe Vaucher Newsgroups: gmane.emacs.devel Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs] Date: Sun, 10 May 2020 00:01:30 +0200 Message-ID: References: <0c88192c-3c33-46ed-95cb-b4c6928016e3@default> <87wo5mc04t.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="5314"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Joost Kremers , Richard Stallman , Emacs developers To: "Alfred M. Szmidt" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 10 00:03:03 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 1jXXYk-0001EN-8I for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 00:03:02 +0200 Original-Received: from localhost ([::1]:43156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXXYi-0000VO-Qw for ged-emacs-devel@m.gmane-mx.org; Sat, 09 May 2020 18:03:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXXXl-0007nc-FR for emacs-devel@gnu.org; Sat, 09 May 2020 18:02:01 -0400 Original-Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]:35045) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jXXXk-0001oJ-Ih; Sat, 09 May 2020 18:02:01 -0400 Original-Received: by mail-lf1-x12f.google.com with SMTP id x73so4298101lfa.2; Sat, 09 May 2020 15:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OStsIG6Det/ZeAZf2n1x2r73T9AeMD0vhPPlmJZhSDs=; b=lJ3dj0tkpUQh+R3/ul0GARVoTvkTmwAQjrHYhOH7dr08IN9cgZqjLWpiL49OS80I7l DU7nPIjLhsZ/1HlJgVqiJefquzBhTV0UY3wBQ7BHbXSeHBxX6EzvEauMPDjgLTswXwpy S6JYZ+D8jior4447Dn2IOP37HN5ZRvfEPDQ84MPWakVyga7PYSncQoHgnje7vASI2G/U glrAAErUeVTR5EcJqvcEMZmUPCQiCIVryx1Hc88CZRbRy1foPveSYn9G89jJWRKIzIe6 VqlDRmX9NrO7iINIlrlpwUcb9pqKjjLKxqwxQpr6DBGLVxXppJO2XVEM95cx243QUC7A smHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OStsIG6Det/ZeAZf2n1x2r73T9AeMD0vhPPlmJZhSDs=; b=olWpaxqGYZm7VA5OAPEE9gRXR3f1fZBCOF+mLToqnisUftflIFKorbKuSK24RRmTnS 8La/pRhRCEve5JftS39XFixbfsqpquptUyJT++oBM8Gay7eNquO6YFpG9LwmUpG4Mwl9 5UOp9T0q+0VlJna2IhI6XBGSP6X0EBziiRUbHF9eSShKMjJ7ice9XraJtVbP/nCjPF49 MBVESlrcstnLNuS2vgH3MxZwFszberqdppm0NTjSqR5o5WGUUZXqYKgLRCrqMPRP98IX 7oX6XLzKJUX6/tqGqMX4/GkjWP6UDum7SP1E6fnAk1JrcONjRKM+qB5c1L4ZAXM/ESnW iOaQ== X-Gm-Message-State: AOAM533APg+vXpH7K3PwmJxfGV/tu5dr06+eRkVtyFI8cVs/jKL36BCT DksFVAOo/jOOmbYxhMUXaHMmmXzMTcmSLlMntmm0JxXl178= X-Google-Smtp-Source: ABdhPJxcube9QbH0wmu/KKzXE6fPCJlWL1zArAyGaT4hp1X2MxpHxFccTnSMyZzmqb+QCTzcgv6NvGTWHu0PWW8osD4= X-Received: by 2002:a05:6512:455:: with SMTP id y21mr6248815lfk.202.1589061717335; Sat, 09 May 2020 15:01:57 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=philippe.vaucher@gmail.com; helo=mail-lf1-x12f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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:249589 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? 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)) > (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) elt exclude)) sequence)))) > 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 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.