Commits

Robert Smith  committed 6c05d16

initial commit

  • Participants

Comments (0)

Files changed (4)

+library for...

File cl-averages.asd

+;;;; cl-averages.asd
+
+(asdf:defsystem #:cl-averages
+  :serial t
+  :description "jkdgjhksd"
+  :author "Robert Smith"
+  :license "public domain"
+  :components ((:file "package")
+               (:file "cl-averages")))
+

File cl-averages.lisp

+;;;; cl-averages.lisp
+
+(in-package #:cl-averages)
+
+;;; SUM returns the sum of LIST
+(defun sum (list)
+  (reduce #'+ list :initial-value 0))
+
+(defun product (list)
+  (reduce #'* list :initial-value 1))
+
+
+(defun arithmetic-mean (&rest nums)
+  "Return the arithmetic mean..."
+  (/ (sum nums)
+     (length nums)))
+
+(defun geometric-mean (&rest nums)
+  (expt (product nums)
+        (/ (length nums))))
+
+(defun harmonic-mean (&rest nums)
+  (/ (length nums)
+     (sum (mapcar #'/ nums))))
+
+

File package.lisp

+;;;; package.lisp
+
+(defpackage #:cl-averages
+  (:use #:cl)
+  (:export #:arithmetic-mean
+           #:geometric-mean
+           #:harmonic-mean)
+  (:nicknames #:avg))
+