From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Klaus-Dieter Bauer Newsgroups: gmane.emacs.devel Subject: Re: Can the byte-compiler check whether functions passed by name are defined? Date: Wed, 7 Aug 2013 17:11:10 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1375888311 9094 80.91.229.3 (7 Aug 2013 15:11:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 7 Aug 2013 15:11:51 +0000 (UTC) Cc: Sebastian Wiesner , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 07 17:11:54 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 1V75Oz-0007WB-OO for ged-emacs-devel@m.gmane.org; Wed, 07 Aug 2013 17:11:53 +0200 Original-Received: from localhost ([::1]:34203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75Oz-0001Tl-9G for ged-emacs-devel@m.gmane.org; Wed, 07 Aug 2013 11:11:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75Oq-0001SZ-Cu for emacs-devel@gnu.org; Wed, 07 Aug 2013 11:11:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V75On-0002No-Sw for emacs-devel@gnu.org; Wed, 07 Aug 2013 11:11:44 -0400 Original-Received: from mail-ve0-x236.google.com ([2607:f8b0:400c:c01::236]:38352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V75On-0002Ne-Ov for emacs-devel@gnu.org; Wed, 07 Aug 2013 11:11:41 -0400 Original-Received: by mail-ve0-f182.google.com with SMTP id m1so1949160ves.13 for ; Wed, 07 Aug 2013 08:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=APIKi/LzWo4W/XW3Y6nJFyDYx9CWVvmxsB0Ybsz/6ZU=; b=dja//+SJ+/bSpzVhSRpdxqYustV0v0Ak8a2cHXcNFexKkphS+mV0q4eVhBuS8w2F3Y auWVSyktgrxSoc5/iwp1Um2jm+P5QvHmg+zhSQTyibdFOrCzwd27KbiyIUCcKuibF5+B dqVTCRcHyL8K89hiGyHI2HhrGF3fHunzEM0FcbWRQx/VD3pxbtkBqGJG96rE+0e4Lza+ oHD9cF4YjGBSkdRXbfEDeUaaZlSmjJANQdyd84eEyuuO8iyNcbzvTyzU1OdLEa62VYCS SDb+YfTppNRnF5k82hGD4QpHrhwmwGRYY3LOA2+j+ccZMxnG0alqLWKH10kh1Z4/GBDJ xMGg== X-Received: by 10.58.75.41 with SMTP id z9mr710437vev.4.1375888300651; Wed, 07 Aug 2013 08:11:40 -0700 (PDT) Original-Received: by 10.220.38.194 with HTTP; Wed, 7 Aug 2013 08:11:10 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400c:c01::236 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:162464 Archived-At: 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 : >>> (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