3 ms·
It would be fun to see these all expressed in Common Lisp's LOOP language, and interesting if any of them didn't work very well. LOOP is a form of crack.
by gruseom 16y ago
It would be fun to see these all expressed in Common Lisp's LOOP language, and interesting if any of them didn't work very well.
LOOP is a form of crack.
- mahmud 16y agoHere ya go! ;; 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))
- gruseom 16y agoVery nice. Thanks.