Created
May 7, 2013 11:33
-
-
Save thinkphp/5531975 to your computer and use it in GitHub Desktop.
to count off a list (a b c) -> ((1 a) (2 b) (3 c))
This file contains hidden or 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
| ;To Count Off a List | |
| ;Adrian Statescu <mergesortv@gmail.com> | |
| ;solution using mapcar | |
| (defun countoff (L &aux (c 0)) | |
| (mapcar #'(lambda (x)(list (setf c (+ c 1)) x) ) L) | |
| ) | |
| ;solution using do | |
| (defun countoff2 (L &aux Result) | |
| (do ((n 1 (+ n 1))(I L (cdr I))) ((null I) (reverse Result)) | |
| (setf Result (cons (list n (car I)) Result)) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment