Then suppose you later need the loop/map to collect some of the values
under certain conditions. You might have
(loop for x in (get-list)
for i from 0
do (format t "~A - ~A~%" i x)
if (test x)
collect (foo x))
Then suppose you later need the loop/map to collect some of the values
under certain conditions. You might have
(loop for x in (get-list)
for i from 0
do (format t "~A - ~A~%" i x)
if (test x)
collect (foo x))
Then suppose you later need the loop/map to collect some of the values under certain conditions. You might have
(loop for x in (get-list)
for i from 0
do (format t "~A - ~A~%" i x)
if (test x)
collect (foo x))
Gauche Scheme
(use srfi-13) ;; string-upcase
(filter-map
(lambda (x i) (print i " - " x)
(and (string? x) (string-upcase x)))
'(foo "an" 8 "why")
(lrange 0))
0 - foo
1 - an
2 - 8
3 - why
("AN" "WHY")
Suppose you have
(loop for x in (get-list)
do (format t "~A~%" x))
and then it turns out you need to print a numeric index. You can do
(loop for x in (get-list)
for i from 0
do (format t "~A - ~A~%" i x))
If you start with
(mapc (lambda (x) (format t "~A~%" x)) (get-list))
it seems (to me) that it'd be harder to modify it as needed,
(let ((list (get-list)))
(mapc (lambda (i x) (format t "~A - ~A" i x))
(range 0 (length list))
list))
(I'm assuming the toolkit includes a RANGE utility, or something similar.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 43:23:34 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,019 |