From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: 65797@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
Joseph Turner <joseph@breatheoutbreathe.in>
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 [thread overview]
Message-ID: <EEBE215B-1F8E-46BF-BE36-AA544AD582C5@gmail.com> (raw)
In-Reply-To: <87v8cmct9b.fsf@breatheoutbreathe.in>
[-- Attachment #1: Type: text/plain, Size: 197 bytes --]
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.)
[-- Attachment #2: apply-partially.diff --]
[-- Type: application/octet-stream, Size: 2591 bytes --]
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))))
next prev parent reply other threads:[~2023-09-07 12:35 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 7:53 bug#65797: 29.0.92; func-arity should not return (0 . many) with apply-partially Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 12:35 ` Mattias Engdegård [this message]
2023-09-07 15:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 15:17 ` Mattias Engdegård
2023-09-07 13:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 15:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 4:40 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 6:46 ` Eli Zaretskii
2023-09-08 15:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 16:37 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 17:18 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 18:16 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 18:20 ` Eli Zaretskii
2023-09-11 16:57 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-11 18:58 ` Eli Zaretskii
2023-09-12 18:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 17:01 ` bug#65797: `buffer-match-p` should not use `func-arity` Philip Kaludercic
2023-09-12 18:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-13 21:50 ` Philip Kaludercic
2023-09-14 13:47 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 9:12 ` Philip Kaludercic
2023-09-18 11:55 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 17:23 ` Philip Kaludercic
2023-09-18 18:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-19 8:34 ` Philip Kaludercic
2023-09-19 10:06 ` Dmitry Gutov
2023-09-19 13:56 ` Philip Kaludercic
2023-09-19 16:13 ` Dmitry Gutov
2023-10-08 9:10 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-08 10:25 ` Dmitry Gutov
2023-10-09 21:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12 4:53 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12 11:34 ` Dmitry Gutov
2023-10-13 15:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-14 6:13 ` Eli Zaretskii
2023-10-14 14:31 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-15 6:13 ` Eli Zaretskii
2023-10-16 16:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-16 20:16 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-19 12:18 ` Eli Zaretskii
2023-10-21 2:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 0:45 ` Dmitry Gutov
2023-09-15 1:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 16:38 ` Dmitry Gutov
2023-09-15 17:54 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 18:00 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EEBE215B-1F8E-46BF-BE36-AA544AD582C5@gmail.com \
--to=mattias.engdegard@gmail.com \
--cc=65797@debbugs.gnu.org \
--cc=joseph@breatheoutbreathe.in \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).