all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: Aidan Kehoe <kehoea@parhasard.net>,
	31792@debbugs.gnu.org, Alan Mackenzie <acm@muc.de>
Subject: bug#31792: 27.0.50; Regression in #'labels, recent versions
Date: Wed, 13 Jun 2018 23:24:50 -0400	[thread overview]
Message-ID: <87muvyvym5.fsf@gmail.com> (raw)
In-Reply-To: <jwvr2labzhg.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Wed, 13 Jun 2018 09:16:01 -0400")

[-- Attachment #1: Type: text/plain, Size: 322 bytes --]

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

> Looks good, but please add a comment before the call to macroexpand-all
> reminding that lexical-let installs a macroexpander for `function` that
> ends up calling cl--labels-convert.

Ok, I extended the docstrings of cl-labels and cl-flet a bit and added a
test too.


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 4900 bytes --]

From c344010e7e2922a75769926896d585d367bbc5a8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Tue, 12 Jun 2018 18:41:46 -0400
Subject: [PATCH] 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".
* lisp/emacs-lisp/cl-macs.el (cl-flet, cl-labels): Improve docstring,
link to relevant manual page.
* test/lisp/emacs-lisp/cl-tests.el (labels-function-quoting): New
test.
---
 lisp/emacs-lisp/cl-macs.el       | 16 ++++++++++++----
 lisp/emacs-lisp/cl.el            |  7 +++++--
 test/lisp/emacs-lisp/cl-tests.el | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 6 deletions(-)
 create mode 100644 test/lisp/emacs-lisp/cl-tests.el

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 9c47ceae18..e80efecac9 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -1964,13 +1964,17 @@ cl--labels-convert
 ;;;###autoload
 (defmacro cl-flet (bindings &rest body)
   "Make local function definitions.
-Like `cl-labels' but the definitions are not recursive.
+Bind the function cells of symbols within FORM.
 Each binding 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)).
 
+The bindings only take effect 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 +2016,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 function definitions.
+Bind the function cells of symbols within FORM.  Each binding can
+take the form (FUNC ARGLIST BODY...) where FUNC is the function
+name, ARGLIST its arguments, and BODY the forms of the function
+body.  The bindings can be referenced from 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)
+
+\f
+
+(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


  reply	other threads:[~2018-06-14  3:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-11 23:11 bug#31792: 27.0.50; Regression in #'labels, recent versions Aidan Kehoe
2018-06-11 23:31 ` Noam Postavsky
2018-06-12 22:58   ` Noam Postavsky
2018-06-13 13:16     ` Stefan Monnier
2018-06-14  3:24       ` Noam Postavsky [this message]
2018-06-14  3:32         ` Stefan Monnier
2018-06-14  4:13           ` Noam Postavsky
2018-06-14 18:05             ` Stefan Monnier
2018-06-20  0:08               ` Noam Postavsky
     [not found] ` <mailman.1699.1528759928.1292.bug-gnu-emacs@gnu.org>
2018-06-13 16:57   ` Alan Mackenzie
2018-06-13 17:03     ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87muvyvym5.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=31792@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=kehoea@parhasard.net \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.