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: Stefan Monnier
Subject: Re: Can the byte-compiler check whether functions passed by name are defined?
Date: Sun, 04 Aug 2013 17:11:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

>  I have written an implementation of the compile-time check, see the
> attached patch to "lisp/bytecomp.el". Since I also introduced as new
> declare form for `defun', I have also attached a patch to
> "doc/functions.texi".

That looks a lot more complex than what I expected.
As mentioned, the best option is to start by adding warnings for the
#'symbol form (should be easy: handle it in the same way we handle
warnings for function calls).

Then make the higher-order functions turn 'symbol into #'symbol.
That's important for things like

   (if foo #'a #'b)

> (defun my-combine (func1 func2)
>   (declare (higher-order-arguments 0 1)

Sadly, I defined the `compiler-macro' declaration to take a function
rather than an exp that returns a function, so you can't just
write a function macroexp--rewrite-function-arguments and then use:

  (defun my-combine (func1 func2)
    (declare (compiler-macro (macroexp--rewrite-function-arguments 0 1)))

But you can do something like
    
  (defun my-combine (func1 func2)
    (declare (compiler-macro
              (lambda (body)
                (macroexp--rewrite-function-arguments
                  body (rewrite func1) (rewrite func2)))))

  (defun my-mapcar (func list)
    (declare (compiler-macro
              (lambda (body)
                (macroexp--rewrite-function-arguments
                  body (rewrite func) list))))

Still, this annotation is only needed to turn a ' into a #', so it's not
the most important.
                  
> I couldn't define the handler in "byte-run.el" however, as when I added it
> to the declaration of `defun-declaration-alist', it would suddenly be
> missing again during compilation.

Probably because you didn't re-dump Emacs (byte-run.el is preloaded
into the `emacs' executable so if you change it, you need to rebuild
`emacs').


        Stefan



reply via email to

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