[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#49316: Add apply-partially's right version
From: |
Michael Heerdegen |
Subject: |
bug#49316: Add apply-partially's right version |
Date: |
Sat, 03 Jul 2021 05:06:18 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
daanturo <daanturo@gmail.com> writes:
> +(defun apply-mid-partially (fun position &rest args)
> + "Return a function that is a partial application of FUN to ARGS at
> POSITION.
I'm not sure if I would prefer that. Personally I guess I would like
something like this instead: A macro that allows partial application
that really looks like an application.
A placeholder (e.g. the symbol `_' which should normally be unbound)
stands for an argument that is used from the args provided in the actual
call:
#+begin_src emacs-lisp
(defmacro applying-partially (call)
(let ((args (make-symbol "args")))
`(lambda (&rest ,args)
(apply #',(car call)
,@(mapcar (lambda (arg)
(if (eq arg '_)
`(pop ,args)
arg))
(cdr call))
,args))))
(defalias 'minus-10 (applying-partially (- _ 10)))
(minus-10 120) ;; ==> 110
(defalias 'my-list-with-some-elts
(applying-partially (list 0 _ 2 _ 4)))
(my-list-with-some-elts 'a 'b 'c 'd) ; => (0 a 2 b 4 c d)
(symbol-function 'my-list-with-some-elts)
;; => (closure (t) (&rest args)
;; (apply #'list 0 (pop args) 2 (pop args) 4 args))
#+end_src
In my eyes that would be more general and a bit better readable (I like
when eldoc works with such stuff).
Regards,
Michael.
- bug#49316: Add apply-partially's right version, (continued)
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/01
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/01
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/01
- bug#49316: Add apply-partially's right version, Eli Zaretskii, 2021/07/01
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/01
- bug#49316: Add apply-partially's right version, Eli Zaretskii, 2021/07/03
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/02
- bug#49316: Add apply-partially's right version, Eli Zaretskii, 2021/07/03
bug#49316: Add apply-partially's right version, Michael Heerdegen, 2021/07/01
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/02
- bug#49316: Add apply-partially's right version,
Michael Heerdegen <=
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/03
- bug#49316: Add apply-partially's right version, Phil Sainty, 2021/07/03
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/05
- bug#49316: Add apply-partially's right version, Phil Sainty, 2021/07/05
- bug#49316: Add apply-partially's right version, Michael Heerdegen, 2021/07/06
- bug#49316: Add apply-partially's right version, daanturo, 2021/07/07