Skip to content

Instantly share code, notes, and snippets.

@lispm
Created February 7, 2017 18:42
Show Gist options
  • Save lispm/7c8bd427a305bab591c15ebb4bca9ec5 to your computer and use it in GitHub Desktop.
Save lispm/7c8bd427a305bab591c15ebb4bca9ec5 to your computer and use it in GitHub Desktop.
; 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