Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created May 7, 2013 11:33
Show Gist options
  • Select an option

  • Save thinkphp/5531975 to your computer and use it in GitHub Desktop.

Select an option

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))
;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