A categorical programming language
Revision | 7e1613d9838bdb57c0a2349e5e4b7363238a3ecf (tree) |
---|---|
Time | 2023-02-16 16:12:46 |
Author | Corbin <cds@corb...> |
Commiter | Corbin |
Add more floating-point operations.
Some NaNs are showing up. I wonder how I should deal with them...
@@ -2,6 +2,8 @@ | ||
2 | 2 | (import scheme |
3 | 3 | matchable) |
4 | 4 | |
5 | + (define (cammy-compile-bin op) (lambda (p) (op (car p) (cdr p)))) | |
6 | + | |
5 | 7 | (define cammy-compile-aux |
6 | 8 | (match-lambda |
7 | 9 | ['id (lambda (x) x)] |
@@ -17,15 +19,23 @@ | ||
17 | 19 | (match-lambda [`(left ,x) (f x)] [`(right ,x) (g x)])] |
18 | 20 | ['t (lambda (_) #t)] ['f (lambda (_) #f)] |
19 | 21 | ['not not] |
22 | + ['conj (lambda (x) (and (car x) (cdr x)))] | |
23 | + ['disj (lambda (x) (or (car x) (cdr x)))] | |
20 | 24 | ['either (lambda (x) (if x '(left *) '(right *)))] |
21 | 25 | ['zero (lambda (_) 0)] |
22 | 26 | ['succ (lambda (n) (+ n 1))] |
27 | + ['n-add (cammy-compile-bin +)] | |
23 | 28 | [`(pr ,f ,g) |
24 | 29 | (lambda (x) |
25 | 30 | (let loop ((n x) (acc (f '*))) |
26 | 31 | (if (= n 0) acc (loop (- n 1) (g acc)))))] |
27 | 32 | ['f-zero (lambda (_) 0.0)] |
28 | 33 | ['f-one (lambda (_) 1.0)] |
34 | + ['f-negate (lambda (f) (- 0.0 f))] | |
35 | + ['f-sin sin] ['f-cos cos] | |
36 | + ['f-add (cammy-compile-bin +)] | |
37 | + ['f-mul (cammy-compile-bin *)] | |
38 | + ['f-lt (cammy-compile-bin <)] | |
29 | 39 | )) |
30 | 40 | |
31 | 41 | (define (cammy-compile expr) |