[plt-scheme] List comprehension style programming

From: wooks (wookiz at hotmail.com)
Date: Thu May 7 18:00:29 EDT 2009

General question. How deep should you layer invocations of HOF's.

Specific example

;; myfunc ::  list of list of numbers -> number
;; returns the number of numbers in the list which has the most non-
zero numbers

;;example (myfunc '((0 0 1 0) (1 2 0 1) (0 1 1 0))) returns 3
;; example (myfunc '((0 0 1 0) (1 2 0 1) (0 1 1 0 8 2))) returns 4

I find myself repeatedly drawn to this sort of code which I hope I am
right in characterising as a list comprehension

      (foldl max 0
             (map length
                  (map (lambda (x)
                         (filter (lambda (y)
                                   (not (zero? y))) x)) some-
list))))))

whereas of course one could write
     (foldl max 0 (some-func-that-produces-list)) or some variation
thereof.

Now I know this is not a very complicated example but how far should
one take this.

Thoughts - opinions?













Posted on the users mailing list.