;; return all permutations of set
;; of subsets (size) of set
(define permutations
(lambda (set size)
(if (null? set)
'(())
(letrec ((f1 (lambda (s)
(map (lambda (e)
(f2 (list e) (cl:remove e s)))
s)))
(f2 (lambda (e s)
(if (= (length e) size)
e
(map (lambda (e2)
(f2 (append e (list e2)) (cl:remove e2 s)))
s)))))
(flatten-1 (f1 set))))))