all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations
@ 2018-02-17 16:04 Clément Pit-Claudel
  2018-02-17 21:58 ` Stefan Monnier
  0 siblings, 1 reply; 31+ messages in thread
From: Clément Pit-Claudel @ 2018-02-17 16:04 UTC (permalink / raw)
  To: Emacs developers

Hey Emacs-devel,

We recently ran into a problem in Flycheck that confused us.  Evaluating the following twice yields different results on the first evaluation (nil) and on the subsequent ones (t):

;; nil on the first run; t on subsequent ones
(progn
  (defmacro m (f)
    `(function ,f))
  (functionp (m (lambda ()))))

Here it is with more info added:

;; "NOK #'(lambda nil)" on the first run; "OK (lambda nil)" on subsequent runs.
(progn
  (defmacro m8 (f)
    `(function ,f))
  (let ((out (m8 (lambda ()))))
    (message "%s %S"
             (if (functionp out) "OK" "NOK")
             out)))

This seems to stem from the way macro-evaluation works: running macroexpand-last-sexp before the first evaluation yields this:

(progn
  (defalias 'm (cons 'macro #'(lambda (f) (list 'function f))))
  (functionp (m #'(lambda nil))))

… but on subsequent evaluations it yields that:

(progn
  (defalias 'm (cons 'macro #'(lambda (f) (list 'function f))))
  (functionp #'(lambda nil)))

Is this expected?  Did we miss something in the manual about this?
Background info: https://github.com/flycheck/flycheck/issues/1398

Thanks!
Clément.



^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2018-03-01  0:50 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-17 16:04 A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations Clément Pit-Claudel
2018-02-17 21:58 ` Stefan Monnier
2018-02-18 15:17   ` Clément Pit-Claudel
2018-02-18 18:02     ` Stefan Monnier
2018-02-25 18:09       ` Clément Pit-Claudel
2018-02-26  3:18         ` Stefan Monnier
2018-02-26  5:40           ` Clément Pit-Claudel
2018-02-26 13:11             ` Stefan Monnier
2018-02-26 15:20               ` Clément Pit-Claudel
2018-02-26 16:31                 ` Stefan Monnier
2018-02-26 16:38                   ` Stefan Monnier
2018-02-26 17:08                     ` Clément Pit-Claudel
2018-02-26 17:31                       ` Stefan Monnier
2018-02-28 14:32                         ` Clément Pit-Claudel
2018-02-28 16:02                           ` Stefan Monnier
2018-02-26 17:01                   ` Clément Pit-Claudel
2018-02-26 17:13                     ` Stefan Monnier
2018-02-26 17:32                       ` Clément Pit-Claudel
2018-02-26 17:40                         ` Clément Pit-Claudel
2018-03-01  0:50                       ` Radon Rosborough
2018-02-27 21:35                     ` Stefan Monnier
2018-02-28 12:44                       ` Michael Heerdegen
2018-02-28 13:31                         ` Stefan Monnier
2018-02-28 14:26                       ` Clément Pit-Claudel
2018-02-28 23:12                         ` Stefan Monnier
2018-02-26 13:13             ` Stefan Monnier
2018-02-26 15:20               ` Clément Pit-Claudel
2018-02-26 16:33                 ` Stefan Monnier
2018-02-26 16:37         ` Michael Heerdegen
2018-02-26 17:15           ` Clément Pit-Claudel
2018-02-26 17:38             ` Stefan Monnier

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.