-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprim.rkt
58 lines (37 loc) · 1.11 KB
/
prim.rkt
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
#lang racket/base
; (require racket/math)
(provide (all-defined-out))
;; Primitives for the ai-scheme interpretation.
;; Pure functional
(define (p_add a b) (+ a b))
(define (p_sub a b) (- a b))
(define (p_mul a b) (* a b))
(define (p_band a b) (bitwise-and a b))
(define (p_bor a b) (bitwise-ior a b))
(define (p_bxor a b) (bitwise-xor a b))
(define (p_and a b) (and a b))
(define (p_or a b) (or a b))
(define (p_not a) (if a 0 1))
(define (p_div a b)
;; Allow for division by zero.
(if (zero? b)
+inf.0
(/ a b)))
(define (p_pow a b) (expt a b))
(define (p_mod a b) (remainder a b))
(define (p_quot a b) (quotient a b))
(define (p_sal a b) (arithmetic-shift a b))
(define (p_sar a b) (arithmetic-shift a (- b)))
(define (p_floor x) (floor x))
;; DSL truth values are bitmasks.
(define (p_lt a b) (if (< a b) -1 0))
(define (p_if c a b) (if (zero? c) b a))
(define (p_exp x) (exp x))
(define (p_sin x) (sin x))
(define (p_cos x) (cos x))
(define (p_log x) (log x))
(define (p_atan x) (atan x))
(define (p_copy x) x)
(define (p_debug x)
(display (format "~a\n" x) (current-error-port))
x)