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 09:55:05 +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="115906"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Joost Kremers , "Alfred M. Szmidt" , Emacs developers To: Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 10 09:56:27 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 1jXgoi-000T5M-5Q for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 09:56:08 +0200 Original-Received: from localhost ([::1]:39278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXgog-0004Co-Lg for ged-emacs-devel@m.gmane-mx.org; Sun, 10 May 2020 03:56:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXgoD-0003ku-6S for emacs-devel@gnu.org; Sun, 10 May 2020 03:55:37 -0400 Original-Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]:38650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jXgoC-0006Qy-39; Sun, 10 May 2020 03:55:36 -0400 Original-Received: by mail-lf1-x142.google.com with SMTP id b26so4806111lfa.5; Sun, 10 May 2020 00:55:34 -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=WrNWB5UdeYTt6movqJ5GDpgU0MdmbludaSEsRVpRkMo=; b=n8ew1sC4tc6jNvh52PEhTWIRaDg2nB/DKJm/Xd5FBiH0qdBdSjp3bhNK8U8fLZiGo/ 1lIg6MOpS1Hic+oaAh3K0TrrrER+A338pNC2cNHGRVhi7gtZDF5E5+d8ko/w2Wt2wObC 3u3/T7pOfPlE6Knr0HX92Bp9qqrfWIu32sw3Q5bAmWSgHio0nKnMG5IjNtl97Uet9IS4 1CCQAXlkmGC30YMqtvQL8rS8qv07cNzwcBN8v/bPBEEjYq5AVV4T9V3aRLT2mnq+fxDo lzAof9BddJZXM7KJNZ443JCodtlbLFFi7djLUgQYlXvIVTOWPUWf/m0Kj1TWNpCCkrtm P3Qw== 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=WrNWB5UdeYTt6movqJ5GDpgU0MdmbludaSEsRVpRkMo=; b=sKNmrReB7p5fdgfLh576azNp123NdAPr+FNwbcwYMzhNeKylskmFiSQwk50PFkSF09 JOuEvLBzyGMwVRn0REzzJ5uY36/iZdMqSRtfvjqmM3oD8i8QfpGj0eHbXjHNh7XzobIY pERuqKrFvm3LO+DEBvvG+iNRkTsZhAF9GjE2tSmd/CvFsHACrEiRRP3uGJWVHQKQjYwA XAtydr+yQX7okoJQRDiVk9DxtpCL2T4rsUyg8pq+oT8qxyn6P5yPijFPslsFOZ4Hb/kr kSL8+65VBxkg70EuOJM4gRY+QQnI3fvWC+7WqzKa8aCTEoMtnEB+vICbGyRrkdaMHC6E InYQ== X-Gm-Message-State: AOAM531+En6d0uI/OcCJhEekMJomAX2YrHc5oRcRXOJGPU02HQq2fgqj m+vzJfK23t5qAupyRXtDvsdY/M/A25+HUovuWXMe6a27OPY= X-Google-Smtp-Source: ABdhPJwK9tjgu3PWebFnFpJh1q4h5gpiO4eZinbQ1MLs6wqmGbKJ0ibn8ojVK+ULSsF23UhayOy3oKKLgP6my0asSUU= X-Received: by 2002:ac2:4248:: with SMTP id m8mr7250113lfl.211.1589097332245; Sun, 10 May 2020 00:55:32 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::142; envelope-from=philippe.vaucher@gmail.com; helo=mail-lf1-x142.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:249640 Archived-At: > Thanks for showing me examples of dash.el. A lot of these facilities > seem useful. I would very much like to see the _documentation_ for how > to use it. Go to https://github.com/magnars/dash.el#functions for its documentation. As soon as you load that page you'd see the documentation, if not scroll a bit down until you read the text. > First, these all seem to be macros, right? Some of them are, some others not. Usually the ones that have double dashes at the beginning are macros, yes. > Why do some names start with a single dash and some with a double dash? I think its simpler for me to copy paste the documentation: All functions and constructs in the library are prefixed with a dash (-). There are also anaphoric versions of functions where that makes sense, prefixed with two dashes instead of one. While -map takes a function to map over the list, you can also use the anaphoric form with double dashes - which will then be executed with it exposed as the list item. Here's an example: (-map (lambda (n) (* n n)) '(1 2 3 4)) ;; normal version (--map (* it it) '(1 2 3 4)) ;; anaphoric version of course the original can also be written like (defun square (n) (* n n)) (-map 'square '(1 2 3 4)) which demonstrates the usefulness of both versions. > About --map-when: > > > (let ((lst '(1 2 3 4))) > > (pp (--map-when (= it 2) 17 lst)) > > (pp (mapcar (lambda (it) (if (= it 2) 17 it)) lst))) > > The map-when version was not self-evident to me. > I had to read the mapcar version to understand its meaning. > Once I did that, it made sense, and I can see that it is useful. > I think we should add this to Emacs, but with a couple of changes. > > * Call it 'map-when' -- why use dashes? Yes, if in Emacs it'll probably have another name. We could also put in seq as seq-map-when. > > 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 > > I will fetch that page and look at it. The point was that until very recently (27.1) there was no flatten function, which is something almost every language has. > (->> '(1 2 3) (-map 'square) (-remove 'even?)) ;; => '(1 9) > > Is '-map' just another name for 'mapcar'? Yes