-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrts.scm
More file actions
46 lines (38 loc) · 1.26 KB
/
rts.scm
File metadata and controls
46 lines (38 loc) · 1.26 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(import (chicken process-context))
(define-syntax curried-lambda
(syntax-rules ()
((curried-lambda () body) body)
((curried-lambda (x . xs) body)
(lambda (x) (curried-lambda xs body)))))
(define-syntax rts-unpack
(syntax-rules ()
((rts-unpack xs () rhs) rhs)
((rts-unpack xs (v . vs) rhs)
(let ((v (car xs)) (rest (cdr xs)))
(rts-unpack rest vs rhs)))))
(define-syntax rts-case-int
(syntax-rules (_)
((rts-case-int tag args)
(error "pattern match failure" (list tag args)))
((rts-case-int tag args (_ rhs) . rest)
rhs)
((rts-case-int tag args ((_ . pvs) rhs) . rest)
(rts-unpack args pvs rhs))
((rts-case-int tag args ((cn . pvs) rhs) . rest)
(if (eq? tag 'cn)
(rts-unpack args pvs rhs)
(rts-case-int tag args . rest)))))
(define-syntax rts-case
(syntax-rules ()
((rts-case s . alts) (rts-case-int (car s) (cdr s) . alts))))
(define Type '(Type))
(define (number->peano z s i)
(if (= i 0)
(list z)
(list s (number->peano z s (- i 1)))))
(define (rts-arg-peano z s i)
(number->peano z s (string->number
(list-ref (command-line-arguments) i))))
(define (rts-arg-read i)
(read (open-input-string
(list-ref (command-line-arguments) i))))