-
Notifications
You must be signed in to change notification settings - Fork 2
/
marburg-utils.rkt
163 lines (131 loc) · 5.04 KB
/
marburg-utils.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#lang racket/base
(require scribble/eval)
(require scribble/base)
(require scribble/core)
(require racket/sandbox)
(require mzlib/pconvert)
(require racket/pretty)
(require file/convertible)
(require 2htdp/image)
(require scribble/manual)
(require teachpack/2htdp/scribblings/img-eval)
(require scribble/decode
scribble/html-properties
scribble/latex-properties)
(provide inbox-style block ev ex vdash stdeval bsl-eval isl-eval+ isl-eval asl-eval todo step multistep equiv prime e e0 e1 e2 e3 e4 eN-1 eN v v1 v2 v3 vN-1 vN x x1 x2 x3 xI xN-1 xN xN eI vI eI-1 eI+1)
(define step (elem "→")) ; (bitmap "arrow.png"))
(define vdash (elem "⊢")) ; (bitmap "arrow.png"))
(define multistep (elem step (superscript "*")))
(define equiv (elem "≡"))
(define e (italic "e"))
(define e0 (elem e (subscript "0")))
(define e1 (elem e (subscript "1")))
(define e2 (elem e (subscript "2")))
(define eI-1 (elem e (subscript "i-1")))
(define eI+1 (elem e (subscript "i+1")))
(define e3 (elem e (subscript "3")))
(define e4 (elem e (subscript "4")))
(define eI (elem e (subscript "i")))
(define eN-1 (elem e (subscript "n-1")))
(define eN (elem e (subscript "n")))
(define v (italic "v"))
(define v1 (elem v (subscript "1")))
(define v2 (elem v (subscript "2")))
(define v3 (elem v (subscript "3")))
(define vI (elem v (subscript "i")))
(define vN-1 (elem v (subscript "n-1")))
(define vN (elem v (subscript "n")))
(define x (italic "x"))
(define x1 (elem x (subscript "1")))
(define x2 (elem x (subscript "2")))
(define x3 (elem x (subscript "3")))
(define xI (elem x (subscript "i")))
(define xN-1 (elem x (subscript "n-1")))
(define xN (elem x (subscript "n")))
(define inbox-style
(make-style "inbox"
(list (make-css-addition "inbox.css")
(make-tex-addition "inbox.tex"))))
(define (prime x) (elem x "'"))
(define (todo text)
'())
(define stdeval (isl-eval+))
(void (interaction-eval #:eval stdeval (require 2htdp/image)))
(void (interaction-eval #:eval stdeval (require 2htdp/abstraction)))
(void (interaction-eval #:eval stdeval (define rocket (bitmap "rocket-s.jpg"))))
(define-syntax block
(syntax-rules ()
[(_ e ...)
(racketblock+eval #:eval stdeval #:escape unsyntax e ...)]))
(define-syntax ev
(syntax-rules ()
[(_ e )
(interaction-eval-show #:eval stdeval e)]))
(define-syntax ex
(syntax-rules ()
[(_ e ...)
(interaction #:eval stdeval e ...)]))
(define-syntax-rule
(*sl-eval module-lang reader def ...)
;; ===>>>
(let ()
(define me (parameterize ([sandbox-propagate-exceptions #f])
(make-img-eval)))
(me '(require (only-in racket empty? first rest cons? sqr true false)))
(me '(require lang/posn))
(me '(require racket/pretty))
(me '(current-print pretty-print-handler))
(me '(pretty-print-columns 65))
(me 'def)
...
(call-in-sandbox-context me (lambda () (error-print-source-location #f)))
(call-in-sandbox-context me (lambda () (sandbox-output 'string)))
(call-in-sandbox-context me (lambda () (sandbox-error-output 'string)))
(call-in-sandbox-context me (lambda () (sandbox-propagate-exceptions #f)))
(call-in-sandbox-context me (lambda ()
(current-print-convert-hook
(let ([prev (current-print-convert-hook)])
;; tell `print-convert' to leave images as themselves:
(lambda (v basic sub)
(if (convertible? v)
v
(prev v basic sub)))))
(pretty-print-size-hook
(let ([prev (pretty-print-size-hook)])
;; tell `pretty-print' that we'll handle images specially:
(lambda (v w? op)
(if (convertible? v) 1 (prev v w? op)))))
(pretty-print-print-hook
(let ([prev (pretty-print-print-hook)])
;; tell `pretty-print' how to handle images, which is
;; by using `write-special':
(lambda (v w? op)
(if (convertible? v) (write-special v op) (prev v w? op)))))
((dynamic-require 'htdp/bsl/runtime 'configure)
(dynamic-require reader 'options))))
(call-in-sandbox-context me (lambda () (namespace-require module-lang)))
(interaction-eval #:eval me (require 2htdp/image))
(interaction-eval #:eval me (require 2htdp/abstraction))
(interaction-eval #:eval me (require 2htdp/batch-io))
(error-display-handler
(lambda (msg exn)
(if (exn? exn)
(display (get-rewriten-error-message exn) (current-error-port))
(eprintf "uncaught exception: ~e" exn))))
me))
(require lang/private/rewrite-error-message)
(define-syntax-rule
(bsl-eval def ...)
(*sl-eval 'lang/htdp-beginner 'htdp/bsl/lang/reader def ...))
(define-syntax-rule
(bsl-eval+ def ...)
(*sl-eval 'lang/htdp-beginner-abbr 'htdp/bsl+/lang/reader def ...))
(define-syntax-rule
(isl-eval def ...)
(*sl-eval 'lang/htdp-intermediate 'htdp/isl/lang/reader def ...))
(define-syntax-rule
(isl-eval+ def ...)
(*sl-eval 'lang/htdp-intermediate-lambda 'htdp/isl/lang/reader def ...))
(define-syntax-rule
(asl-eval def ...)
(*sl-eval 'lang/htdp-advanced 'htdp/asl/lang/reader def ...))