[plt-scheme] Do Scheme programmers use the 'do' form very often?
Grant Rettke writes:
> Do Scheme programmers use the 'do' form very often?
I use it sometimes. Here's a recent usage (variable names changed to
protect the innocent):
(do ((n 1 (add1 n)) (l l (cdr l)))
((null? l))
(let ((x (car l)))
;; code involving n and x that is evaluated for side-effect,
;; e.g. printing, or updating a database
...))
This seems nicer than constructing a list of 1..(length l) and using
for-each, but that's a matter of taste. Probably there's some more
elegant way to do it using iterations/comprehensions but I haven't
delved into that part of the new manual yet.
...Wait, okay, I just did, and this is how I'd do it now:
(for ((n (in-naturals 1)) (x l))
...)
Learn something new every day!
--dougorleans at gmail.com