emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A combination of defmacro, functionp, and quoted lambdas yields differen


From: Clément Pit-Claudel
Subject: A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations
Date: Sat, 17 Feb 2018 11:04:07 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]