unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Klaus-Dieter Bauer <bauer.klaus.dieter@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Sebastian Wiesner <lunaryorn@gmail.com>, emacs-devel@gnu.org
Subject: Re: Can the byte-compiler check whether functions passed by name are defined?
Date: Wed, 7 Aug 2013 17:11:10 +0200	[thread overview]
Message-ID: <CANtbJLGKTHwas7d4WFSWfEFGLHuT0=j0ya+qOHrCz=LVrWRKWw@mail.gmail.com> (raw)
In-Reply-To: <jwva9kt7ejj.fsf-monnier+emacs@gnu.org>

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 <monnier@iro.umontreal.ca>:
>>> (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	other threads:[~2013-08-07 15:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29 10:35 Can the byte-compiler check whether functions passed by name are defined? Klaus-Dieter Bauer
2013-07-29 15:21 ` Stefan Monnier
2013-07-31 13:44   ` Klaus-Dieter Bauer
2013-07-31 17:49     ` Stefan Monnier
2013-07-31 18:01       ` Sebastian Wiesner
2013-08-01 20:31         ` Stefan Monnier
2013-08-04 18:41           ` Klaus-Dieter Bauer
2013-08-04 21:11             ` Stefan Monnier
2013-08-05  8:52               ` Klaus-Dieter Bauer
2013-08-05 14:35                 ` Stefan Monnier
2013-08-05 18:17                   ` Klaus-Dieter Bauer
2013-08-07 11:27                     ` Klaus-Dieter Bauer
2013-08-07 14:41                     ` Stefan Monnier
2013-08-07 15:11                       ` Klaus-Dieter Bauer [this message]
2013-08-07 15:21                         ` Stefan Monnier
2013-08-07 17:34                           ` Stefan Monnier
2013-08-07 21:11                             ` Glenn Morris
2013-08-07 21:59                               ` Glenn Morris
2013-08-08  1:25                                 ` Stefan Monnier
2013-08-08  8:44                                   ` Klaus-Dieter Bauer
2013-08-08 13:07                                     ` Stefan Monnier
2013-08-07 19:59                           ` Klaus-Dieter Bauer
2013-08-07 21:14                             ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANtbJLGKTHwas7d4WFSWfEFGLHuT0=j0ya+qOHrCz=LVrWRKWw@mail.gmail.com' \
    --to=bauer.klaus.dieter@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=lunaryorn@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).