This works:
(+ 1 2 3) 6
This doesn't work:
(+ '(1 2 3))
This works if 'cl-*
' is loaded:
(reduce '+ '(1 2 3)) 6
If reduce
were always available I could write:
(defun sum (L) (reduce '+ L)) (sum '(1 2 3)) 6
What is the best practice for defining functions such as sum
?
(apply '+ '(1 2 3))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With