From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#65797: 29.0.92; func-arity should not return (0 . many) with apply-partially Date: Thu, 7 Sep 2023 14:35:17 +0200 Message-ID: References: <87v8cmct9b.fsf@breatheoutbreathe.in> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_C475B530-B778-429D-AC68-E9F6BBAF65A0" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19571"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , Joseph Turner To: 65797@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 07 14:36:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qeEFD-0004sr-VG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Sep 2023 14:36:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeEEv-0008Lu-J2; Thu, 07 Sep 2023 08:36:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeEEt-0008Je-GB for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 08:36:04 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeEEq-0002Xq-QS for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 08:36:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeEEs-0002z4-De for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 08:36:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87v8cmct9b.fsf@breatheoutbreathe.in> Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Sep 2023 12:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65797 X-GNU-PR-Package: emacs Original-Received: via spool by 65797-submit@debbugs.gnu.org id=B65797.169409012911401 (code B ref 65797); Thu, 07 Sep 2023 12:36:02 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 7 Sep 2023 12:35:29 +0000 Original-Received: from localhost ([127.0.0.1]:38798 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeEEL-0002xp-3b for submit@debbugs.gnu.org; Thu, 07 Sep 2023 08:35:29 -0400 Original-Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:56568) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeEEI-0002xb-R8 for 65797@debbugs.gnu.org; Thu, 07 Sep 2023 08:35:28 -0400 Original-Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-500a8b2b73eso1446945e87.0 for <65797@debbugs.gnu.org>; Thu, 07 Sep 2023 05:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694090119; x=1694694919; darn=debbugs.gnu.org; h=to:cc:date:message-id:subject:mime-version:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=Xye8gW6YwT59aFcdJLJH2wxY1oQEmX41N4Fk1NZa5os=; b=UiYU07JMJ/hkeGHTevhkfN3s0QX8qzrjExHk473V81spIZ+ClhfTtgJAcLm32rkpUC VzIY5IzVViudg9NtYBVm6kXaTWhRBT00u/ojUyrK0mfYKhGeHh2+AlQpv4FtJ9KoQMYV Hg7Qr0keq9w+6qQ1KhDuxJObCqIITlXBfedIehVJY6rYqjP4nXmkBbsUUhy2EoJpbNsl h3xnsl6jpbsFMhdYXjhWbP757OLk39i4dVms9BJgjA5pcaob6FqyPoXcIhB9sQIL1vMa H77DWamAtMow+mPIEY3BsCiIJENuxl+2YoST8RYZLAVgibzenLD13t4ryxytrocihkcF ZjoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694090119; x=1694694919; h=to:cc:date:message-id:subject:mime-version:from:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Xye8gW6YwT59aFcdJLJH2wxY1oQEmX41N4Fk1NZa5os=; b=l1cRBLdRys+Uix+DzAW1SAKbKOAyHLn/Xyb+4bsLLlguq/kiJXFXSneqY+luJsjFBp NpA6+pj/IxXTyXOH6qu9Q7BvlTC/o8GoYw19EZbbDWUzQdtAaVZBoFmT90IGRsnCqE9y h3dJNXFulDXW4bNlbq1knFJEaPQOjiMvDIuWPlK0XI0kvnY6CZ504USmqsqlHNxT9NMa 8nzu6F/PlTTtaaRaUy1pR6QQBCSQudzBG9Wg1MjUJfUF11t7nImei+HR4GxiEOeQvQTs xk0RDvpr8x5ZbFCjSjWDvsuszp8JHnFFIwtbqoluXp9Lj4KTXhQvU++T0+dbIr+cl9XJ Ao6g== X-Gm-Message-State: AOJu0YzeYlVrKWwzhLKNZt/AoeIoR8wkmrEvFmCiVDchgsclmZeZDTv/ L5Fgb2TraXuMdS4NuHL/mErxiwyHYjc= X-Google-Smtp-Source: AGHT+IFTaLzXX7pG0jmGtHjXswoYYHmrqjhaMlQtZfkAgio9k8Nohu8AxOQb5qiWVrBPhy36ldjyrQ== X-Received: by 2002:a19:ca03:0:b0:500:9d4a:89f8 with SMTP id a3-20020a19ca03000000b005009d4a89f8mr3649121lfg.28.1694090118894; Thu, 07 Sep 2023 05:35:18 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id o9-20020ac24949000000b00500b561285bsm3137947lfi.292.2023.09.07.05.35.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2023 05:35:18 -0700 (PDT) X-Mailer: Apple Mail (2.3654.120.0.1.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269645 Archived-At: --Apple-Mail=_C475B530-B778-429D-AC68-E9F6BBAF65A0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Here is one way, but it's mainly aimed at improving performance, not = guaranteeing a particular function signature. (Yet another reason to avoid using buffer-match-p as far as I'm = concerned.) --Apple-Mail=_C475B530-B778-429D-AC68-E9F6BBAF65A0 Content-Disposition: attachment; filename=apply-partially.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="apply-partially.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/subr.el b/lisp/subr.el index 34d87e83310..9c701241b7e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -519,13 +519,50 @@ frame-configuration-p (and (consp object) (eq (car object) 'frame-configuration))) +(defun internal--compiler-macro-apply-partially (form &optional fun-arg + &rest args) + (if (and fun-arg (null args)) + fun-arg + (let ((fun (and (memq (car-safe fun-arg) '(quote function)) + (cadr fun-arg)))) + (if (and (symbolp fun) (functionp fun) (not (autoloadp fun))) + (let* ((arity (func-arity fun)) + (min-args (car arity)) + (max-args (cdr arity)) + (nargs (length args))) + (cond + ((eq max-args 'many) form) + ((> nargs max-args) + (macroexp-warn-and-return + (format-message + "`%s' called with %d partial args for `%s' (max is %d)" + (car form) nargs fun max-args) + form)) + (t ; (<= nargs max-args) + (let* ((min-extra-args (max (- min-args nargs) 0)) + (max-extra-args (- max-args nargs)) + (extra-args + (mapcar (lambda (i) (make-symbol (format "x%d" i))) + (number-sequence 1 max-extra-args))) + (fargs (mapcar (lambda (i) (make-symbol (format "a%d" i))) + (number-sequence 1 nargs)))) + `(let ,(mapcar (lambda (i) (list (nth i fargs) (nth i args))) + (number-sequence 0 (1- nargs))) + (lambda (,@(take min-extra-args extra-args) + ,@(and (> max-extra-args min-extra-args) + (cons '&optional + (nthcdr min-extra-args extra-args)))) + (,fun ,@fargs ,@extra-args))))))) + form)))) + (defun apply-partially (fun &rest args) "Return a function that is a partial application of FUN to ARGS. ARGS is a list of the first N arguments to pass to FUN. The result is a new function which does the same as FUN, except that the first N arguments are fixed at the values with which this function was called." - (declare (side-effect-free error-free)) + (declare (side-effect-free error-free) + (compiler-macro internal--compiler-macro-apply-partially)) (lambda (&rest args2) (apply fun (append args args2)))) --Apple-Mail=_C475B530-B778-429D-AC68-E9F6BBAF65A0--