-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combinators for n-ary functions (use apply instead of funcall) #72
Conversation
N-ary versions of -on, -not, -orfn, -andfn New combinators -rotate-args and -reverse-args for rotating/reversing arglist of n-ary functions. Altered items: -on2, -rotate-args, -reverse-args, -not2, -orfn2, -andfn2,
You might want to replace the original -on, -not, -orfn, -andfn with the new versions |
Thanks! I'll ping @Fuco1 for this one. |
Personally I find The main issue here, however, is speed. Funcall is slow as it is but apply is much much slower. I did a quick benchmark calling
3000 times on a list of 1000 strings (all files byte-compiled) and the results are
This is definitely something you could feel in the result product. I suspect the rest would be equally slowed down. I can't imagine right now a use case for "ternary Also we should add the types to all the functions... but I'm not sure how to express variable arguments. Maybe |
How about adding fast binary versions with funcall since these are most likely to be used (e.g. |
What you mean adding? The present functions all use funcall when possible. Edit: Oh, you mean like adding binary, ternary, ... using funcall and then a generic one for n-ary use? Dunno if that wouldn't be too much noise..... |
or how about an extra parameter to indicate the arity? (implemented as macros) |
This is a rewrite and extension of PR #72 to address issue #306. For discussion, especially wrt performance, see PRs #72 and #308. * dash.el (-on, -flip, -not, -orfn, -andfn): Return a variadic function. Declare as pure and side-effect-free. (-rotate-args): New combinator suggested by @vapniks in PR #72. (-const): Declare as pure and side-effect-free. * NEWS.md (2.19.0): Announce -rotate-args and variadic combinators. * dev/examples.el (-partition-after-pred): Fix oddp bug waiting to happen with negative dividends. (-cons*): Check that &rest args are safe to mutate. (-on, -flip, -const, -not, -orfn, -andfn): Extend tests. (-rotate-args): New test. * README.md: * dash.texi: Regenerate docs.
N-ary versions of -on, -not, -orfn, -andfn
New combinators -rotate-args and -reverse-args for rotating/reversing
arglist of n-ary functions.
Altered items:
-on2, -rotate-args, -reverse-args, -not2, -orfn2, -andfn2,