Last active
August 29, 2015 14:03
-
-
Save arademaker/2534d4d9bee74eaeebe1 to your computer and use it in GitHub Desktop.
linked lists and vectors
This file contains 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
; 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