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: emacs-devel@gnu.org
Subject: Re: Can the byte-compiler check whether functions passed by name are defined?
Date: Wed, 31 Jul 2013 15:44:39 +0200	[thread overview]
Message-ID: <CANtbJLGJhgwpkiGNngNMchUSHnhoyFmRO3ggFosh9Zh4oPSiBQ@mail.gmail.com> (raw)
In-Reply-To: <jwviozte6jq.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2006 bytes --]

2013/7/29 Stefan Monnier <monnier@iro.umontreal.ca>

> >     (mapcar 'my-function-1 some-list)?
>
> We could do it for symbols quoted with #' but not for quoting with '.
>
>         Stefan
>

#' would allow checking for a defined function independent of the function,
the function is oassed to, true... Would require however to change coding
practice to using this syntax, with the advantage of preventing warnings
when people don't want the check but the disadvantage, that the warning is
also supressed when people just don't care. I guess it would still be the
best solution, that is backward compatible though.

Another possibilty (probably less good though):

    (eval-and-compile
      (put 'mapcar 'compiler-macro
           (lambda (&rest form)
             (let ((function (nth 1 form)))
               (when (and (macroexp--compiling-p)
          (listp function)
                          (= 2 (length function))
                          (member (nth 0 function) '(function quote))
                          (symbolp (nth 1 function))
                          (not (fboundp (nth 1 function))))
                 (warn "Function not know to be defined: %S" (nth 1
function))))
     (car form))))

    (mapcar 'message '("Hello" "World"))
    (mapcar 'foobar '("Foo" "Bar"))

Some caveats here:
1. Has to be done, though maybe through a macro, for every higher-order
function.
2. `compiler-macro' doesn't seem to be documented anywhere. The arguments
the function gets passed seem to differ from case to case...
3. (warn) doesn't emit warnings to the compilation buffer but to the
separate *Warnings* buffer, making this code only a prrof-of-concept
without practical value.
4. If the quoted funciton is defined in the same file as the higher-order
function it is passed to, the definition of the quoted function must be
both before the first use of the function and inside an (eval-and-compile
..) block, which can only be prevented by changes to the compiler code
anyway.

kind regards, Klaus

[-- Attachment #2: Type: text/html, Size: 3720 bytes --]

  reply	other threads:[~2013-07-31 13:44 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 [this message]
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
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=CANtbJLGJhgwpkiGNngNMchUSHnhoyFmRO3ggFosh9Zh4oPSiBQ@mail.gmail.com \
    --to=bauer.klaus.dieter@gmail.com \
    --cc=emacs-devel@gnu.org \
    --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).