summaryrefslogtreecommitdiff
path: root/sieve/extra-functional.scm
blob: ab480c06890ea51517b68cc022438e1ffb80fddf (plain)
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

(library (extra-functional)
    (export curry uncurry flip part compose)
    (import (rnrs base))



(define (curry f)
    (lambda (x)
        (lambda (y . r)
            (apply f (cons x (cons y r))))))



(define (uncurry f)
    (lambda (x y . r)
        (apply (f x) (cons y r))))



(define (flip f)
    (lambda (x y . r)
        (apply f (cons y (cons x r)))))



(define-syntax part
    (syntax-rules () ((_ f x)
        ((curry f) x))))



(define-syntax dot
    (syntax-rules ()
        ((_ x f) (f x))
        ((_ x f g ...) (f (dot x g ...)))))



; (compose f g h) => (lambda (x) (f (g (h x))))
(define-syntax compose
    (syntax-rules ()
        ((_ f ...) (lambda (x) (dot x f ...)))))



)