GNU bug report logs - #27016
possible bug in `defsetf'

Previous Next

Package: emacs;

Reported by: Rafael D Sorkin <rsorkin <at> perimeterinstitute.ca>

Date: Mon, 22 May 2017 06:40:01 UTC

Severity: minor

Tags: fixed, patch

Found in versions 24.4, 25.2

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: npostavs <at> users.sourceforge.net
Cc: 27016 <at> debbugs.gnu.org, Rafael D Sorkin <rsorkin <at> perimeterinstitute.ca>
Subject: bug#27016: possible bug in `defsetf'
Date: Tue, 23 May 2017 01:10:09 +0200
npostavs <at> users.sourceforge.net writes:

> Oh, right, I see it now.  It happens in 24.4 and later.  I'm not sure
> it's a bug though.  My guess is that the difference is eager
> macroexpansion.  When I compile, then I get the same behaviour with 24.3
> (that's my earliest working Emacs build) as well.

(require 'cl)

(macroexpand-1 (macroexpand-1 (macroexpand-1 '(defsetf foobar setcar))))
==>

#+begin_src emacs-lisp
(gv-define-expander foobar
  (lambda
    (do &rest args)
    (gv--defsetter 'foobar
                   (lambda
                     (val &rest args)
                     `(,'setcar ,@args ,val))
                   do args)))
#+end_src

A comment in the definition of `gv-define-expander' says:

  ;; Use eval-and-compile so the method can be used in the same file as it
  ;; is defined.
  ;; FIXME: Just like byte-compile-macro-environment, we should have something
  ;; like byte-compile-symbolprop-environment so as to handle these things
  ;; cleanly without affecting the running Emacs.

Anyway, the above expands to

(macroexpand-1 (macroexpand-1 (macroexpand-1 (macroexpand-1 '(defsetf foobar setcar)))))
==>

#+begin_src emacs-lisp
(eval-and-compile
  (put 'foobar 'gv-expander
       (lambda
         (do &rest args)
         (gv--defsetter 'foobar
                        (lambda
                          (val &rest args)
                          `(,'setcar ,@args ,val))
                        do args))))
#+end_src

The `put' is evaluated when the `defsetf' macro call is expanded.
That's what's causing the issue.

AFAIK we don't say that `defsetf' is only allowed at top level, so I
would say (without any judgement) that it's a bug.  And it's not limited
to `defsetf' in "cl".


Michael.




This bug report was last modified 7 years and 290 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.