From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: Codifying some aspects of Elisp code style and improving pretty printer Date: Fri, 01 Oct 2021 18:15:18 +0200 Message-ID: <8735pk202x.fsf@gmail.com> References: <87o88bntv8.fsf@gmail.com> <87wnmyy29v.fsf@gmail.com> <871r56nlhd.fsf@gmail.com> <87v92hw7gq.fsf@gnus.org> <87a6js253t.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14537"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Bozhidar Batsov , akater , Emacs Devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 01 18:18:43 2021 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 1mWLFC-0003ap-Qa for ged-emacs-devel@m.gmane-mx.org; Fri, 01 Oct 2021 18:18:42 +0200 Original-Received: from localhost ([::1]:58976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWLFB-0004CW-Kg for ged-emacs-devel@m.gmane-mx.org; Fri, 01 Oct 2021 12:18:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWLC3-00018a-O3 for emacs-devel@gnu.org; Fri, 01 Oct 2021 12:15:32 -0400 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:40606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWLBz-00080u-OR for emacs-devel@gnu.org; Fri, 01 Oct 2021 12:15:27 -0400 Original-Received: by mail-wr1-x42e.google.com with SMTP id s21so16275220wra.7 for ; Fri, 01 Oct 2021 09:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-transfer-encoding; bh=hCOjDiYMTPi+71Cxe85912dCjcLtX3Vcj0NvMytit1Y=; b=CkMp4uA/ABmMvBSabxhc1WAzrIgQCAN4GYKV+Nq9VqW4i3O00dMcG3mqLZTMf8L4sQ vAIOf4AweIc7bOUgRDVoY147OafPFrZhv73Au1eOL2DREiVg47YULaTskkqAPOFyyGuL w0DxJ0n8XezxDG8w8GcNgw275uxv05xbKf/145I2ITvy6Llwmt4IfOUaQEJxFa2YHmR8 y2Si+/4PJ7YrQbe5ufSwVLIGamWibG62Iv3auHsn9uHuaWqqm5iy7BIpyowGvN6maDt0 1qvMgchAMo0P0/h3THsUCXdptoHpErSn1KN76qqzHu30IIahqHbtffD6y71VZ/rvXEuZ WB1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=hCOjDiYMTPi+71Cxe85912dCjcLtX3Vcj0NvMytit1Y=; b=SFRd/wPXzZ/fz9EOPK8erNZlRqiHhTd9fDMvmaP8jIR/MtNbrYznglmsNuqM5MhP1K 5l1vYzmZqAcE9/gP0gqsTurs/qMCWXx48IQ+5RwAsDyZ1v3wFww4Q7uutt1vySH9NIxC R9hcYJUh3H/mcql/DQ6Ul9T24/5DCeXs6M7XQXmwiogk20j/aIwOVh5/yMA29I5HSBoV WNBU2334Ym2FYrhg7SwbfgdYTq3Wv/7DyVdNgo3wE0ZJPAxJKlcdHGZubRVikGuri7T/ EZMeWOGe6vFuI2z9sIC/02W9PQccjdwRL5XlFO2OS80wSRxM1ei1dAonG3qfJlxQ6eIr ssLg== X-Gm-Message-State: AOAM531x0Gl2LEFR5+2dXyqNrtvR6gu1Qv56lHxYkWEg7vOAfqXTPOLo YvSL6vd9PQmKYqE3VTzwmnb3kMIQBZM= X-Google-Smtp-Source: ABdhPJyOXflgJcy1QE338SMkFOoHr6ztz0Zj5M2zymBHeY7jwHCWQ08VamuMMGuoKEHQWUjKhH2axg== X-Received: by 2002:a05:6000:550:: with SMTP id b16mr13851293wrf.297.1633104919632; Fri, 01 Oct 2021 09:15:19 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id j4sm6261290wrt.67.2021.10.01.09.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 09:15:19 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Fri, 01 Oct 2021 11:26:51 -0400") Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=rpluim@gmail.com; helo=mail-wr1-x42e.google.com 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_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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:275993 Archived-At: >>>>> On Fri, 01 Oct 2021 11:26:51 -0400, Stefan Monnier said: >> Apropos, I believe the current recommendation is to do >> (mapconcat #'identity seqs " ") >> rather than >> (mapconcat 'identity seqs " ") >> ie function-quoting the argument to mapconcat, apply, mapc etc, but Stefan> Indeed, the main benefit being that the byte-compiler can warn = you if Stefan> the function is not known to be defined (typically because of a= typo or Stefan> a missing `require`). Stefan> A side benefit is that it "does the right thing" for `cl-flet` = and friends. >> 1. The elisp manual doesn=CA=BCt say that in (info "(elisp) Mapping = Functions") Stefan> Not sure that'd be the best place, but we should probably adjus= t the Stefan> manual to encourage the use of #' to quote function names, All the examples there use 'quote', and the discussion of 'quote' vs 'function' is in (info "(elisp) Anonymous Functions"). People who've just gone 'i mapc' in the elisp manual have no reason to read that second node. Patch below >> 2. Emacs' code itself doesn=CA=BCt do that consistently Stefan> The difference is sufficiently unimportant that I don't see a n= eed to Stefan> try and make it consistent in this respect. E.g. I do change '= foo to Stefan> #'foo quite often, but only as part of other changes. OK. That=CA=BCs ~900 spurious changes we can avoid making :-) >> (and we have the odd #'(lambda ...) as well Stefan> I don't see anything wrong with #'(lambda...) Stefan> [ I personally prefer to skip the #' to make the code (marginal= ly) Stefan> shorter, but it's purely a matter of taste and I usually try = and Stefan> refrain from making this change in existing code unless it he= lps make Stefan> the code fit into 80 columns. ] If dislike it, because I view lambda as self-quoting, but as you say that=CA=BCs a personal preference (although "(elisp) Anonymous Functions" kind of tells you not to quote lambda's). >> 3. The byte compiler doesn=CA=BCt warn about it. Stefan> Mine does ;-) Stefan> But I wouldn't want to enable such a warning by default (or at = least it Stefan> should be mess a bit less eager than it is, because of the occa= sional false Stefan> positives). I=CA=BCve not seen any false positives from mine, but I suspect it=CA=BCs l= ess sophisticated than yours :-) >> I believe it helps the byte-compiler generate better code, but don= =CA=BCt >> know what the actual effect is. Stefan> It has no effect on the generated code. OK, so no code change, but how about: diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index c856557c3c..4416b39f09 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -890,6 +890,33 @@ Mapping Functions over a char-table in a way that deals properly with its sparse nature, use the function @code{map-char-table} (@pxref{Char-Tables}). =20 + All the mapping functions described here take a function as their +first argument, which can be specified in different ways: + +@itemize +@item An anonymous lambda + +@example +(mapcar (lambda (x) (x)) ....) +@end example + +@item A function-quoted symbol + +@example +(mapcar #'identity ....) +@end example + +@item An quoted symbol + +@example +(mapcar 'car ....) +@end example +@end itemize + +The last two are equivalent, except that function-quoting can help the +byte-compiler warn if the function being called is +undefined. @xref{Anonymous Functions} for more information. + @defun mapcar function sequence @anchor{Definition of mapcar} @code{mapcar} applies @var{function} to each element of @var{sequence}