From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#31792: 27.0.50; Regression in #'labels, recent versions Date: Thu, 14 Jun 2018 00:13:50 -0400 Message-ID: <87h8m6vwch.fsf@gmail.com> References: <5b1f.0188.5dc11.f21c@parhasard.net> <878t7kzyqs.fsf@gmail.com> <87k1r3y5m2.fsf@gmail.com> <87muvyvym5.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1528949587 21563 195.159.176.226 (14 Jun 2018 04:13:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 14 Jun 2018 04:13:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: Aidan Kehoe , 31792@debbugs.gnu.org, Alan Mackenzie To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 14 06:13:03 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fTJd8-0005Su-Nx for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jun 2018 06:13:02 +0200 Original-Received: from localhost ([::1]:38107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTJfF-0004m4-T2 for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Jun 2018 00:15:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTJf7-0004ln-Ew for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2018 00:15:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTJf4-0006ZO-6d for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2018 00:15:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fTJf3-0006ZI-Vy for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2018 00:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fTJf3-0007y9-RN for bug-gnu-emacs@gnu.org; Thu, 14 Jun 2018 00:15:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Jun 2018 04:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31792 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 31792-submit@debbugs.gnu.org id=B31792.152894964230543 (code B ref 31792); Thu, 14 Jun 2018 04:15:01 +0000 Original-Received: (at 31792) by debbugs.gnu.org; 14 Jun 2018 04:14:02 +0000 Original-Received: from localhost ([127.0.0.1]:47212 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fTJe6-0007wZ-5p for submit@debbugs.gnu.org; Thu, 14 Jun 2018 00:14:02 -0400 Original-Received: from mail-it0-f48.google.com ([209.85.214.48]:35238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fTJe2-0007vw-Bq for 31792@debbugs.gnu.org; Thu, 14 Jun 2018 00:14:01 -0400 Original-Received: by mail-it0-f48.google.com with SMTP id a3-v6so6933360itd.0 for <31792@debbugs.gnu.org>; Wed, 13 Jun 2018 21:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=FXLd+n1bwgMiDoHTB7FBUfTqV+I//81XReFerKRitE8=; b=EKrRB+H+CX5nCLxm7a/oTbEX5N/n2k+9Y14Bz7lNHUUBOswcmi76G2xMuV6HGoluP4 Kn0CeYWR5DXcb9GMcBoTxU7I/pCjhzDOoF1Nzdlfk2d5GALdoeuns0I046ifzX8u1Kmw vkHQcsA9eTx4gEigixqYnYDOlvbLFRXuJnQHcb2Eym3iz/RP/rBQPKqzFSNXlu/hAxbT TbZ+rz1lRvVem6LgH6okvmLXuy7guGILzFmJTE7IQAT2Q3cN1Ze/M2QmZ5o5w4+iCQ6c 3VeNCoab78rnsOqzoJu/pg8lJbJIfETEHspPCxMNer/cpxLflxQ0rbN9G9j91prOJoiw Tr1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=FXLd+n1bwgMiDoHTB7FBUfTqV+I//81XReFerKRitE8=; b=l8MFL1PJrMabS2mvdoET/M0hECCLnJSALYntqNME/Ad2QbzWLzRMVsrPfrUw5bNP1W 4M+ag2rFaubHsoFoTcSQbLdp/vh0NjGW28qPEN1u7Zb7rbkbBawes9//mSmOs2HugEmN a5vMS7Dnk9GoFnqAGY+LJqDJ9mWmPoSNe6L3RR/A5VbzcVQYVG28ZqKwv9k5TaKbnaTc AUtOijN7PRArOTL5FQA3Ia52Qo6M949YvS86ldLnfEI2FLJriaSC3QtyL3voSx0DXbVh daWEhSFYqrH7O5Jkem+H5gBzgjmgkz1COEZoMNmDgjVaElgcE9NMcdmxPvtZfHWlGt7+ pN2w== X-Gm-Message-State: APt69E2jnzfdIL3QJIJ2UVCTd/RgI8OfbLsNWcjvT0HLeika9WuvMZ5h CVVH7R9ucqQiOI5DdSvGMPo= X-Google-Smtp-Source: ADUXVKLN3vHE0x8qGSOOBG7zcOJ1sYeMLLDLd6TsBK9WnhazBig6wGGgdtwvv/qvSXv+DnnmSUO2pQ== X-Received: by 2002:a24:148f:: with SMTP id 137-v6mr713415itg.58.1528949632927; Wed, 13 Jun 2018 21:13:52 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id z6-v6sm2428355ita.21.2018.06.13.21.13.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 21:13:51 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Wed, 13 Jun 2018 23:32:02 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147397 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >> +Bind the function cells of symbols within FORM. > > I think this is wrong: it makes it sound like it does `fset`, which > is what CL's `flet` did, but not what `cl-flet` does. > If you look at the implementation, you'll see that it doesn't touch any > "function cell". Hmm, the manual page says something similar: -- Macro: cl-flet (bindings...) forms... This form establishes `let'-style bindings on the function cells of symbols rather than on the value cells. It also wrongly claims that (quote FUNC) would work: A "reference" to a function name is either a call to that function, or a use of its name quoted by `quote' or `function' to ^^^^^^^ be passed on to, say, `mapcar'. Perhaps both of those are leftovers from the original `flet' description. How about this: --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v3-0001-Fix-fun-handling-inside-labels-Bug-31792.patch Content-Description: patch >From f83d79ca2707f4bbe0bc1b0a74ee78d7cc64cbe5 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Tue, 12 Jun 2018 18:41:46 -0400 Subject: [PATCH v3] Fix #'fun handling inside `labels' (Bug#31792) * lisp/emacs-lisp/cl.el (labels): Apply the equivalent of the cl-labels change from 2015-01-16 "* lisp/emacs-lisp/cl-macs.el: Fix last change". * test/lisp/emacs-lisp/cl-tests.el (labels-function-quoting): New test. * lisp/emacs-lisp/cl-macs.el (cl-flet, cl-labels): Improve docstring, link to relevant manual page. * doc/misc/cl.texi (Function Bindings): Don't imply that function cells of symbols are modified by cl-flet. Don't claim that cl-flet or cl-labels affect references of the form (quote FUNC). --- doc/misc/cl.texi | 23 ++++++++++------------- lisp/emacs-lisp/cl-macs.el | 17 ++++++++++++----- lisp/emacs-lisp/cl.el | 7 +++++-- test/lisp/emacs-lisp/cl-tests.el | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 test/lisp/emacs-lisp/cl-tests.el diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index bf85b00e93..553b935b1e 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -1299,17 +1299,18 @@ Function Bindings of variables. @defmac cl-flet (bindings@dots{}) forms@dots{} -This form establishes @code{let}-style bindings on the function -cells of symbols rather than on the value cells. Each @var{binding} -must be a list of the form @samp{(@var{name} @var{arglist} -@var{forms}@dots{})}, which defines a function exactly as if -it were a @code{cl-defun} form. The function @var{name} is defined -accordingly but only within the body of the @code{cl-flet}, hiding any external -definition if applicable. +This form establishes @code{let}-style bindings for functions rather +than values. Each @var{binding} must be a list of the form +@samp{(@var{name} @var{arglist} @var{body}@dots{})}. Within +@var{forms}, any reference to the function @var{name} uses the local +definition instead of the global one. + +A ``reference'' to a function name is either a call to that function, +or a use of its name quoted by @code{function} to be passed on to, +say, @code{mapcar}. The bindings are lexical in scope. This means that all references to -the named functions must appear physically within the body of the -@code{cl-flet} form. +the named functions must appear physically within @var{forms}. Functions defined by @code{cl-flet} may use the full Common Lisp argument notation supported by @code{cl-defun}; also, the function @@ -1336,10 +1337,6 @@ Function Bindings the functions themselves. Thus, @code{cl-labels} can define local recursive functions, or mutually-recursive sets of functions. -A ``reference'' to a function name is either a call to that -function, or a use of its name quoted by @code{quote} or -@code{function} to be passed on to, say, @code{mapcar}. - Note that the @file{cl.el} version of this macro behaves slightly differently. @xref{Obsolete Macros}. @end defmac diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 9c47ceae18..0854e665b9 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -1964,13 +1964,16 @@ cl--labels-convert ;;;###autoload (defmacro cl-flet (bindings &rest body) "Make local function definitions. -Like `cl-labels' but the definitions are not recursive. -Each binding can take the form (FUNC EXP) where +Each definition can take the form (FUNC EXP) where FUNC is the function name, and EXP is an expression that returns the function value to which it should be bound, or it can take the more common form \(FUNC ARGLIST BODY...) which is a shorthand for (FUNC (lambda ARGLIST BODY)). +FUNC is defined only within FORM, not BODY, so you can't write +recursive function definitions. Use `cl-labels' for that. See +info node `(cl) Function Bindings' for details. + \(fn ((FUNC ARGLIST BODY...) ...) FORM...)" (declare (indent 1) (debug ((&rest (cl-defun)) cl-declarations body))) (let ((binds ()) (newenv macroexpand-all-environment)) @@ -2012,9 +2015,13 @@ cl-flet* ;;;###autoload (defmacro cl-labels (bindings &rest body) - "Make temporary function bindings. -The bindings can be recursive and the scoping is lexical, but capturing them -in closures will only work if `lexical-binding' is in use. + "Make local (recursive) function definitions. +Each definition can take the form (FUNC ARGLIST BODY...) where +FUNC is the function name, ARGLIST its arguments, and BODY the +forms of the function body. FUNC is defined in any BODY, as well +as FORM, so you can write recursive and mutually recursive +function definitions. See info node `(cl) Function Bindings' for +details. \(fn ((FUNC ARGLIST BODY...) ...) FORM...)" (declare (indent 1) (debug cl-flet)) diff --git a/lisp/emacs-lisp/cl.el b/lisp/emacs-lisp/cl.el index d53c8e0bbc..f6643158d2 100644 --- a/lisp/emacs-lisp/cl.el +++ b/lisp/emacs-lisp/cl.el @@ -466,9 +466,12 @@ labels (push var sets) (push (cons (car binding) `(lambda (&rest cl-labels-args) - (cl-list* 'funcall ',var - cl-labels-args))) + (if (eq (car cl-labels-args) cl--labels-magic) + (list cl--labels-magic ',var) + (cl-list* 'funcall ',var cl-labels-args)))) newenv))) + ;; `lexical-let' adds `cl--function-convert' (which calls + ;; `cl--labels-convert') as a macroexpander for `function'. (macroexpand-all `(lexical-let ,vars (setq ,@sets) ,@body) newenv))) ;; Generalized variables are provided by gv.el, but some details are diff --git a/test/lisp/emacs-lisp/cl-tests.el b/test/lisp/emacs-lisp/cl-tests.el new file mode 100644 index 0000000000..b673822cd9 --- /dev/null +++ b/test/lisp/emacs-lisp/cl-tests.el @@ -0,0 +1,35 @@ +;;; cl-tests.el --- tests for emacs-lisp/cl.el -*- lexical-binding:t -*- + +;; Copyright (C) 2018 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see `https://www.gnu.org/licenses/'. + +;;; Commentary: + +;;; Code: + +(require 'cl) +(require 'ert) + + + +(ert-deftest labels-function-quoting () + "Test that #'foo does the right thing in `labels'." ; Bug#31792. + (should (eq (funcall (labels ((foo () t)) + #'foo)) + t))) + +;;; cl-tests.el ends here -- 2.11.0 --=-=-=--