[plt-scheme] List comprehension style programming
On Thu, May 7, 2009 at 6:00 PM, wooks <wookiz at hotmail.com> wrote:
> General question. How deep should you layer invocations of HOF's.
I would write this with the `for' set of list comprehensions/loops.
Here's your example, with no extra traversals:
(define (f l)
(for/fold ([k 0])
([e l])
(max k
(for/fold ([k 0]) ([i e] #:when (not (zero? i))) (add1 k)))))
(f '((0 0 1 0) (1 2 0 1) (0 1 1 0)))
(f '((0 0 1 0) (1 2 0 1) (0 1 1 0 8 2)))
--
sam th
samth at ccs.neu.edu