Skip to content

Instantly share code, notes, and snippets.

@arademaker
Last active August 29, 2015 14:03
Show Gist options
  • Save arademaker/2534d4d9bee74eaeebe1 to your computer and use it in GitHub Desktop.
Save arademaker/2534d4d9bee74eaeebe1 to your computer and use it in GitHub Desktop.
linked lists and vectors
; first version: procedural
(defun nth-1 (n alist)
(let ((current alist))
(dotimes (v n current)
(if (equal v n)
(car current)
(setf current (cdr current))))))
; second version: functional
(defun nth-2 (n alist)
(if (equal n 0)
alist
(nth-2 (- n 1) (cdr alist))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment