-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitives.rkt
30 lines (23 loc) · 935 Bytes
/
primitives.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
#lang racket
(provide primitives-namespace)
(require syntax/parse/define
"domain.rkt")
(define primitives-namespace (make-base-namespace))
(define-syntax-parse-rule (define-primitive id:id expr)
(namespace-set-variable-value! 'id expr #t primitives-namespace #t))
(define-syntax-parse-rule (define-primitive/lift id:id expr)
(define-primitive id (lift expr)))
(define ((lift proc) . args)
(cond
[(not (procedure-arity-includes? proc (length args))) (⊥ "arity mismatch")]
[(andmap natural? args) (apply proc args)]
[else T]))
(define-primitive/lift read
(lambda () T))
(define-primitive/lift error
(lambda () (⊥ "error")))
(define-primitive/lift + (procedure-reduce-arity + 2))
(define-primitive/lift - (procedure-reduce-arity - 2))
(define-primitive/lift * (procedure-reduce-arity * 2))
(define-primitive/lift / (procedure-reduce-arity / 2))
(define-primitive/lift = (procedure-reduce-arity = 2))