How to sum a list of numbers in Emacs Lisp?

前端 未结 7 2137
夕颜
夕颜 2021-01-31 09:08

This works:

(+ 1 2 3)
6

This doesn\'t work:

(+ \'(1 2 3))

This works if \'cl-*\' is loaded:

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 09:31

    If you manipulate lists and write functional code in Emacs, install dash.el library. Then you could use its -sum function:

    (-sum '(1 2 3 4 5)) ; => 15
    

提交回复
热议问题