-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutilities.lisp
28 lines (24 loc) · 1.02 KB
/
utilities.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;;;; utilities.lisp
;;;;
;;;; Copyright (c) 2014 Robert Smith
;;;;
;;;; This file contains various utilities.
(in-package #:formulador)
(defun minimum (items &key (key 'identity)
(otherwise 0))
"Comptue the minimum value of ITEMS, optionally applying the unary function KEY to each item. If there are no items, return OTHERWISE, which is 0 by default."
(if (null items)
otherwise
(loop :for item :in items
:minimize (funcall key item))))
(defun maximum (items &key (key 'identity)
(otherwise 0))
"Comptue the maximum value of ITEMS, optionally applying the unary function KEY to each item. If there are no items, return OTHERWISE, which is 0 by default."
(if (null items)
otherwise
(loop :for item :in items
:maximize (funcall key item))))
(defun sum (items &key (key 'identity))
"Compute the sum of ITEMS, optionally applying the unary function KEY to each item."
(loop :for item :in items
:sum (funcall key item)))