emacs-devel
[Top][All Lists]
Advanced

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

Re: Can the byte-compiler check whether functions passed by name are def


From: Klaus-Dieter Bauer
Subject: Re: Can the byte-compiler check whether functions passed by name are defined?
Date: Wed, 7 Aug 2013 17:11:10 +0200

The patch only adds a single line of code to byte-compile-normal-call
which calls defun byte-compile--higher-order--check-arguments.

@@ -2960,6 +2964,7 @@
 (defun byte-compile-normal-call (form)
   (when (and (byte-compile-warning-enabled-p 'callargs)
              (symbolp (car form)))
+    (byte-compile--higher-order--check-arguments form)
     (if (memq (car form)
               '(custom-declare-group custom-declare-variable
                                      custom-declare-face))
@@ -4659,6 +4664,177 @@


Here the lines


+    (dolist (subform (cdr form))
+      (setq pos (1+ pos))
+      ;; Check when subform has form (function SYMBOL) or (quote SYMBOL)
+      ;; and position matches one mentioned in
higher-order-arguments.+      (when (or (and (listp subform) ;; case:
(function SYMBOL)
+      (when (or (and (listp subform) ;; case: (function SYMBOL)
+                    (eq (car subform) 'function)
+                    (symbolp (car (cdr subform)))
+                    (null (cdr (cdr subform))))
+               (and (listp subform) ;; case: (quote SYMBOL)
+                    (eq (car subform) 'quote)
+                    (symbolp (car (cdr subform)))
+                    (null (cdr (cdr subform)))
+                    (member pos higher-order-arguments)))

decide whether the argument will be considered a quoted function and
corresponding checks will be performed or not.

The first part of the `or' checks for arguments of the form (function
SYMBOL), the second part for arguments of the form (quote SYMBOL)
where for the called function's name, i.e. (car form), the position of
the (quote SYMBOL) argument is one of the integers in the list stored
in the property 'higher-order-arguments (stored to a local variable to
avoided repeated `get' calls). The in new version of the patch
(*.patch-2) additionally a warning is printed in the (quote SYMBOL)
case asking the user to change it to #'SYMBOL.

  - Klaus

2013/8/7 Stefan Monnier <address@hidden>:
>>> (mapcar (if flag #'f1 #'f2) list)
>>> and `f1' or `f2' are unknown.
>
>> My code does that and indeed that was, what I first implemented.
>
> Could you point to the place where your code does that?
> It should be a few lines of extra code in byte-compile-function-form,
> but I couldn't find it in your patch.
>
>
>         Stefan



reply via email to

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