Created
February 7, 2017 18:42
-
-
Save lispm/7c8bd427a305bab591c15ebb4bca9ec5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; linear-search returns the position of item in the list | |
(defun linear-search (list item &aux (pos 0)) | |
(dolist (e list nil) | |
(if (eql e item) | |
(return pos) | |
(incf pos)))) | |
(defun linear-search (list item &aux (pos 0)) | |
(map nil | |
(lambda (e) | |
(when (eql e) | |
(return-from linear-search pos))) | |
list)) | |
(defun linear-search (list item) | |
(loop for pos from 0 and element in list | |
when (eql item element) | |
do (return pos))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment