-
Notifications
You must be signed in to change notification settings - Fork 2
/
prelude.ss
36 lines (30 loc) · 1012 Bytes
/
prelude.ss
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
;; Our by-now usual prelude.
(define (compiler-error . bobbins)
(error bobbins))
(define (runtime-error . bobbins)
(error bobbins))
;; A unique value for uninitialised variables.
(define undefined-value '(constant . undefined))
(define (init* self . fields)
(define (init1 fields)
(if (pair? fields)
(if (pair? (cdr fields))
(begin
((car fields) self (cadr fields))
(init1 (cddr fields)))
(error "Field spec not in format (:mutator! value ...)" fields))))
(init1 fields))
(define-macro (-> value . rest)
(cond
((null? rest)
value)
((pair? rest)
(let ((next (car rest)))
(if (pair? next)
`(-> (,(car next) ,value ,@(cdr next)) ,@(cdr rest))
`(-> (,next ,value) ,@(cdr rest)))))))
;; A working implementation of compose, since it seems to be missing from SISC
(define (compose . procs)
(if (null? procs)
(lambda (v) v)
(lambda (v) ((car procs) ((apply compose (cdr procs)) v)))))