Line | |
---|
1 | ;;;; logical-combinators.scm |
---|
2 | ;;;; Kon Lovett, Mar '09 |
---|
3 | |
---|
4 | (module logical-combinators |
---|
5 | |
---|
6 | (;export |
---|
7 | andf |
---|
8 | orf) |
---|
9 | |
---|
10 | (import scheme chicken data-structures srfi-1) |
---|
11 | |
---|
12 | (declare |
---|
13 | (type |
---|
14 | (andf (procedure (#!rest) *)) |
---|
15 | (orf (procedure (#!rest) *)) ) ) |
---|
16 | |
---|
17 | ;; Eager 'or' & 'and' |
---|
18 | |
---|
19 | (define (andf . args) |
---|
20 | (let loop ((args args) (prev #t)) |
---|
21 | (if (null? args) |
---|
22 | prev |
---|
23 | (let ((cur (car args))) |
---|
24 | (and cur (loop (cdr args) cur) ) ) ) ) ) |
---|
25 | |
---|
26 | (define (orf . args) |
---|
27 | (let loop ((args args)) |
---|
28 | (and |
---|
29 | (not (null? args)) |
---|
30 | (or (car args) (loop (cdr args)) ) ) ) ) |
---|
31 | |
---|
32 | ) ;module logical-combinators |
---|
Note: See
TracBrowser
for help on using the repository browser.