- unordered-subset-for-each f listprocedure
- unordered-subset-for-each f list kprocedure
Iterate over every k-combination (partial unordered subset) of list, calling f for its side effect.
- f
- The function to call
- list
- The list to permute
- k
- k distinct elements (default: n)
(define unordered-subset-for-each (case-lambda ((f list) (unordered-subset-for-each f list (length list))) ((f list k) (let ((subset (make-vector k)) (n (length list))) (let iter ((start 0) (p 0)) (if (= p k) (f (project subset list)) (do ((i start (+ i 1))) ((= i n)) (vector-set! subset p i) (iter (add1 i) (add1 p)))))))))