Search code examples
emacslispelisp

What's the equivalent of foldr, foldl in Emacs Lisp?


What's the equivalent of foldr, foldl in Emacs Lisp?


Solution

  • Since Emacs-24.3 we recommend the use of cl-lib over cl (which is planned for removal in some distant future), so it would be:

    (require 'cl-lib)
    (cl-reduce #'+ '(1 2 3 4))
    

    and since Emacs-25, you can also use the seq package for that:

    (require 'seq)
    (seq-reduce #'+ '(1 2 3 4) 0)