-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.scm
69 lines (52 loc) · 1.23 KB
/
bootstrap.scm
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(define (fact x)
(if (= x 0) 1
(* x (fact (- x 1)))))
(define (fib x)
(if (<= x 1) x
(+ (fib (- x 1))
(fib (- x 2)))))
(define (<= a b)
(or (< a b) (= a b)))
(define (> a b)
(not (<= a b)))
(define (>= a b)
(or (> a b) (= a b)))
(define (length x)
(if (null? x) 0
(+ 1 (length (cdr x)))))
(define (memoize fn comp)
(letrec ((get (lambda (query) '(#f)))
(set (lambda (query value)
(let ((old-get get))
(set! get (lambda (q)
(if (comp q query)
(cons #t value)
(old-get q))))))))
(lambda args
(let ((cache (get args)))
(if (car cache)
(cdr cache)
(let ((call (apply fn args)))
(set args call)
call))))))
(define mfib (memoize (lambda (x)
(if (< x 2) x
(+ (mfib (- x 1)) (mfib (- x 2)))))
equal?))
(define (list . args) args)
(define (reload) (load "bootstrap.scm"))
(define t 'temp)
(define (go) (+ 1 (call/cc (lambda (c) (set! t c) 1))))
(define (append a b)
(if (null? a)
b
(cons (car a)
(append (cdr a) b))))
(define (map fun lst)
(if (null? lst)
'()
(cons (fun (car lst))
(map fun (cdr lst)))))
(define display print)
(define call-with-current-continuation call/cc)
(load "testing/mt.scm")