emacs-devel
[Top][All Lists]
Advanced

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

Re: Is there a function for auto currying in Elisp?


From: John Wiegley
Subject: Re: Is there a function for auto currying in Elisp?
Date: Thu, 21 Dec 2017 13:04:37 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (darwin)

>>>>> "v" == vlnx  <address@hidden> writes:

v> Nicolas Petton writes:
>> I've been looking for a function that would automatically curry its
>> argument, but couldn't find it. Maybe I just missed it?

v> This may be what you are looking for:

v> #+BEGIN_SRC emacs-lisp
v> (defun funcall-list (funcs list)
v>   "Apply `funcall' of each FUNCS on LIST, recursively defined"
v>   (if (car funcs)
v>       (funcall-list (cdr funcs)
v>                     (funcall (car funcs) list))
v>     list))
v> #+END_SRC

Sometimes I also want:

(defun traverse (f x)
  "Visit all nodes within the sexp X, apply F to its leaves."
  (cond ((consp x)
         (cons (traverse f (car x))
               (traverse f (cdr x))))
        ((listp x)
         (mapcar (apply-partially #'traverse f) x))
        ((hash-table-p x)
         (maphash #'(lambda (key value)
                      (puthash key (traverse f value) x)) x))
        (t (funcall f x))))

Do we have a function already that visits every visitable "node" within a
sexp?

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



reply via email to

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