From a89c2f9bd895ae08093fcd137abf2a3c93b53df7 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 20 Jul 2020 10:48:34 -0400 Subject: feat(gs/emacs): Add an "average" util function I've been using this in some literate org scripts lately Change-Id: I42830fb30dd77c9b04fcc9373cafcef05fa8b837 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1322 Tested-by: BuildkiteCI Reviewed-by: glittershark --- users/glittershark/emacs.d/utils.el | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'users/glittershark') diff --git a/users/glittershark/emacs.d/utils.el b/users/glittershark/emacs.d/utils.el index c595b46ce2..1bfac3ca8b 100644 --- a/users/glittershark/emacs.d/utils.el +++ b/users/glittershark/emacs.d/utils.el @@ -10,6 +10,15 @@ (defun inc (x) "Returns x + 1" (+ 1 x)) (defun dec (x) "Returns x - 1" (- x 1)) +(defun average (ns) + "Arithmetic mean of xs" + (if (null ns) nil + (/ (apply #'+ ns) + (length ns)))) + +(comment + (average (list 1 2 3 4)) + ) ;; ;; Text editing utils -- cgit 1.4.1