blob: 611aaca71c1ea428c33fb2653cb1eca5136e9840 (
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
|
(define-module (com simatime core))
(define (flip f) (lambda (x y) (f y x)))
(define (curry f a) (lambda (b) (apply f (cons a (list b)))))
(define pos?
(curry < 0))
(define neg?
(curry > 0))
(define (foldr f end lst)
(if (null? lst)
end
(f (car lst) (foldr f end (cdr lst)))))
(define (foldl f acc lst)
(if (null? lst)
acc
(foldl f (f acc (car lst)) (cdr lst))))
(define fold foldl)
(define (unfold f init pred)
(if (pred init)
(cons init '())
(cons init (unfold f (f init) pred))))
(define (sum lst) (fold + 0 lst))
(define (produce lst) (fold * 0 1 lst))
(define count length)
;;
;; clojure-like stuff
;;
(define (pr . a)
(for-each display args))
(define (prn . a) (apply pr a) (newline))
|