Skip to content

Instantly share code, notes, and snippets.

@kosciCZ
Forked from animatedlew/len.lisp
Created April 26, 2017 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosciCZ/856764125479e0afe43af3daebabe757 to your computer and use it in GitHub Desktop.
Save kosciCZ/856764125479e0afe43af3daebabe757 to your computer and use it in GitHub Desktop.
Recursively finding the length of a list in Lisp.
(defun len (list)
(if list
(1+ (len (cdr list)))
0))
@kosciCZ
Copy link
Author

kosciCZ commented Apr 26, 2017

This recurcsively counts list items. it cuts off first item, adds one to the count and then calls itself on the shortened list. When it hits zero items, it starts to return recursively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment