Subject: Re: bug#27016: possible bug in `defsetf'

From: Rafael D Sorkin <[email-masked]>
Date: Mon, 22 May 2017 18:03:08 -0400

Thanks, I was wondering about that myself.  Is there a standard
for elisp (or common lisp) that would determine whether eager
macro expansion is an error in this case?

I would expect that a `defun' or `defsetf' etc which is within a
conditional would not be executed until it was known whether the
condition was satisfied.  The opposite behavior seems
counter-intuitive to me.

But if you decide that this behavior is not a bug, then please
let me know, so that I can adapt to it in the future.

 > tags 27016 - unreproducible
 > found 27016 24.4
 > found 27016 25.2
 > quit
 > 
 > Rafael D Sorkin <[email-masked]> writes:
 > 
 > > Following your suggestion I tried starting with "emacs -Q" and
 > > got the same results as you did.  However if I (require 'cl)
 > > then the bug returns.  (I normally require CL automatically on
 > > starting emacs.)  So perhaps it's an incompatibility between CL
 > > and the new way that defsetf is implemented.
 > 
 > 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.
 > 
 >     $ emacs -Q -batch -l cl -f batch-byte-compile bug-27016-defsetf.el 
 > 
 >     In toplevel form:
 >     bug-27016-defsetf.el:1:1:Warning: cl package required at runtime
 >     bug-27016-defsetf.el:3:1:Warning: global/dynamic var `pair' lacks a prefix
 >     Wrote /home/npostavs/src/emacs/bug-27016-defsetf.elc
 >     $ emacs -Q -batch -l bug-27016-defsetf.elc
 >     pair: (0 . 4)
 > 
 > where bug-27016-defsetf.el has contents:
 > 
 >     (require 'cl)
 > 
 >     (defvar pair nil)
 >     (setq pair (cons 3 4))                  ; (3 . 4)
 >     (unless t
 >       (defalias 'foobar 'cons)
 >       (defsetf foobar setcar))              ; nil
 >     (setf (foobar pair) 0)                  ; 0       !
 > 
 >     (message "pair: %S" pair)

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 Rafael Sorkin
 Perimeter Institute for Theoretical Physics
 31 Caroline Street North
 Waterloo, ON  N2L 2Y5
 Canada
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-