From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Can the byte-compiler check whether functions passed by name are defined? Date: Wed, 31 Jul 2013 13:49:19 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1375292979 29954 80.91.229.3 (31 Jul 2013 17:49:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 31 Jul 2013 17:49:39 +0000 (UTC) Cc: emacs-devel@gnu.org To: Klaus-Dieter Bauer Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 31 19:49:40 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V4aWq-0008Mu-ED for ged-emacs-devel@m.gmane.org; Wed, 31 Jul 2013 19:49:40 +0200 Original-Received: from localhost ([::1]:48344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4aWq-000063-3U for ged-emacs-devel@m.gmane.org; Wed, 31 Jul 2013 13:49:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4aWf-00005p-8K for emacs-devel@gnu.org; Wed, 31 Jul 2013 13:49:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4aWX-0003cI-HB for emacs-devel@gnu.org; Wed, 31 Jul 2013 13:49:29 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:6881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4aWX-0003c2-C1 for emacs-devel@gnu.org; Wed, 31 Jul 2013 13:49:21 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFFpZvt/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLNBIUGA0kLodwBsEtkQoDklqSIIFegxM X-IPAS-Result: Av4EABK/CFFFpZvt/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLNBIUGA0kLodwBsEtkQoDklqSIIFegxM X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="20263660" Original-Received: from 69-165-155-237.dsl.teksavvy.com (HELO pastel.home) ([69.165.155.237]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 31 Jul 2013 13:49:14 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 1FC4466249; Wed, 31 Jul 2013 13:49:20 -0400 (EDT) In-Reply-To: (Klaus-Dieter Bauer's message of "Wed, 31 Jul 2013 15:44:39 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:162301 Archived-At: > #' 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. Stefan