;; Linear Search
(defun find-a-grade (grades)
(loop for grade in grades
when (char= grade #\a)
return grade))
;; Guarded Linear Search
; should use condition system to signal exhaustion
(defun surely-find-a-grade (grades)
(loop for grade in grades
when (char= grade #\a)
return grade
finally (return "not found")))
;; Definate process all items
; fn is a unary function that gets applied to each element in sequence
(defmethod search-all ((objects sequence) fn)
(loop for item in objects do
(funcall fn item)))
;fn is a BINARY function that gets applied to each key/value pair
(defmethod search-all ((objects hash-table) fn)
(maphash fn objects))
;; Polling loop
(defun amy-poller (eof question)
(loop for answer = (yes-or-no-p question)
when answer
return "bye"))
;; extreme values
(defun maximum (values)
(loop for val in values
maximize val))
(defun minimum (values)
(loop for val in values
minimize val))