Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 45:47:12 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,336 |
Pascal J. Bourguignon wrote:
(defun counting (list &optional (from 1))
(mapcar (let ((i (1- from)))
(lambda (x)
(if (consp x)
(cons (incf i) x)
(list (incf i) x))))
list))
(let ((arguments '(aa bb cc)))
(format t "~:{~A. ~A~%~}" (counting arguments)))
1. AA
2. BB
3. CC
Gauche Scheme
(define (print-counted the-list :optional (from 0))
(for-each
(lambda (i x) (print i ". " x))
(lrange from)
the-list))
gosh> (print-counted '(a bb ccc))
0. a
1. bb
2. ccc
gosh> (print-counted '(a bb ccc) 233)
233. a
234. bb
235. ccc
Shorter:
(define (print-counted the-list :optional (from 0))
(for-each
(cut print <> ". " <>)
(lrange from)
the-list))
(print-counted '(aa bb cc) 700)700. aa