[Top][All Lists]

[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: Wed, 31 Jul 2013 13:49:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> #' 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.

The two aren't mutually exclusive.  I'd welcome a patch that adds the
warning when #' is used.

>     (eval-and-compile
>       (put 'mapcar 'compiler-macro
>            (lambda (&rest form)

This should be (lambda (form &rest args)

Warning from a (compiler) macro is a pain in the rear (because the macro
might be called in difference circumstances and because it's not called
at a good time).  But if #' warns, then the compiler-macro can simply
turn 'foo into #'foo and leave the warning to the handle of #'.

> 1. Has to be done, though maybe through a macro, for every higher-order
> function.

Note that macroexp.el already has special handling for the main
higher-order functions (to warn about '(lambda ...)).  So it could be
implemented there.

> 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.

You can try to use macroexp--warn-and-return.

> 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.

That's why the patch for #' warnings needs to be directly in bytecomp.el
rather than in compiler macros.


reply via email to

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