GNU bug report logs -
#27016
possible bug in `defsetf'
Previous Next
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
Message #31 received at 27016 <at> debbugs.gnu.org (full text, mbox):
Rafael D Sorkin <rsorkin <at> perimeterinstitute.ca> writes:
> 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?
CLTL says this[1]:
The evaluator is typically implemented as an interpreter that traverses
the given form recursively, performing each step of the computation as
it goes. An interpretive implementation is not required, however. A
permissible alternative approach is for the evaluator first to
completely compile the form into machine-executable code and then invoke
the resulting code. This technique virtually eliminates
incompatibilities between interpreted and compiled code but also renders
the evalhook mechanism relatively useless. Various mixed strategies are
also possible. All of these approaches should produce the same results
when executing a correct program but may produce different results for
incorrect programs. For example, the approaches may differ as to when
macro calls are expanded; macro definitions should not depend on the
time at which they are expanded. Implementors should document the
evaluation strategy for each implementation.
and this[2] specifically about defsetf:
X3J13 voted in March 1989 (DEFINING-MACROS-NON-TOP-LEVEL) to clarify
that, while defining forms normally appear at top level, it is
meaningful to place them in non-top-level contexts; the complex form of
defsetf must define the expander function within the enclosing lexical
environment, not within the global environment.
I'm not sure whether (unless ...) counts as an "enclosing lexical
environment" though.
> 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.
`defun' takes effect at runtime (or rather it expands to `defalias'
which operates at runtime), whereas `defsetf' has to affect subsequent
compilation, so waiting until runtime to decide whether the condition is
true could not really work.
> 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.
I *think* it's not a bug, or at least not one worth fixing. If you wrap
your (unless ...) form in (eval-when-compile ...) then you get your
expected behaviour.
[1]: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node179.html
[2]: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node80.html
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.