Skip to content

Instantly share code, notes, and snippets.

@terry3
Last active March 3, 2016 09:28
Show Gist options
  • Save terry3/8c91acbf044ef7e28fd6 to your computer and use it in GitHub Desktop.
Save terry3/8c91acbf044ef7e28fd6 to your computer and use it in GitHub Desktop.
The recursive implement of get n-th element in list
;; The recursive implement of get n-th element in list
(defun get-n (x y)
(if (eql x 0)
(car y)
(get-n (- x 1) (cdr y))))
(write-line (get-n 0 '("a" "b" "c" "d" "e")))
(write-line (get-n 1 '("a" "b" "c" "d" "e")))
(write-line (get-n 2 '("a" "b" "c" "d" "e")))
(write-line (get-n 3 '("a" "b" "c" "d" "e")))
(write-line (get-n 4 '("a" "b" "c" "d" "e")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment