/usr/lib/combine.scm is in scheme9 2013.11.26-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | ; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; Placed in the Public Domain
;
; (combine integer list) ==> list
; (combine* integer list) ==> list
; (load-from-library "combine.scm")
;
; Create k-combinations of the elements of the given list. K (the
; size of the combinations) is specified in the integer argument.
; COMBINE creates combinations without repetition, and COMBINE*
; creates combinations with repetition.
;
; Example: (combine 2 '(a b c)) ==> ((a b) (a c) (b c))
; (combine* 2 '(a b c)) ==> ((a a) (a b) (a c)
; (b b) (b c) (c c))
(define (combine3 n set rest)
(letrec
((tails-of
(lambda (set)
(cond ((null? set)
'())
(else
(cons set (tails-of (cdr set)))))))
(combinations
(lambda (n set)
(cond
((zero? n)
'())
((= 1 n)
(map list set))
(else
(apply append
(map (lambda (tail)
(map (lambda (sub)
(cons (car tail) sub))
(combinations (- n 1) (rest tail))))
(tails-of set))))))))
(combinations n set)))
(define (combine n set)
(combine3 n set cdr))
(define (combine* n set)
(combine3 n set (lambda (x) x)))
|