-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscheme.red
More file actions
24 lines (24 loc) · 1.28 KB
/
scheme.red
File metadata and controls
24 lines (24 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(define CAR (template (x) (first x)))
(define CDR (template (x) (rest x)))
(define CONS (template (x y) (prepend x y)))
(define NULL (template (x) (empty? x)))
(define < (template (x y) (preceed? x y)))
(define = (template (x y) (equal? x y)))
(define > (template (x y) (preceed? y x)))
(define + (template (x y) (sum x y)))
(define - (template (x y) (sum x (product y -1))))
(define * (template (x y) (product x y)))
(define / (function (x y) (if (< x y) 0 (+ 1 (/ (- x y) y)))))
(define % (function (x y) (- x (* (/ x y) y))))
(define LAMBDA (template (args body) (function args body)))
(define MAP (function (select combine identity list) (if (empty? list) identity (combine (select list) (MAP select combine identity (rest list))))))
(define MAPCAR (function (F L) (MAP (function (x) (F (CAR x))) CONS '() L)))
(define Y (LAMBDA (X) ((LAMBDA (P) (X (LAMBDA (A) ((P P) A)))) (LAMBDA (P) (X (LAMBDA (A) ((P P) A)))))))
(define FACT (Y (LAMBDA (F) (LAMBDA (N) (if (= 0 N) 1 (* N (F (- N 1)))))) ))
(define fCONS (LAMBDA (A D) (LAMBDA (M) (M A D))))
(define fCAR (LAMBDA (X) (X (LAMBDA (A D) A))))
(define fCDR (LAMBDA (X) (X (LAMBDA (A D) D))))
(define f (function (x) (g (h x))))
(define g (function (x) (if (> x 0) (f (- x 4)) (h x))))
(define h (function (x) (* x 2)))
'(Scheme Loaded)