bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#49316: Add apply-partially's right version


From: daanturo
Subject: bug#49316: Add apply-partially's right version
Date: Sat, 3 Jul 2021 13:17:50 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

That's cool! Can you submit the patch?

On 7/3/21 10:06 AM, Michael Heerdegen wrote:
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

--
Daanturo.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]