nendo 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -118,3 +118,61 @@
118
118
  (assv-ref "expanded" alist))))))))
119
119
 
120
120
 
121
+ (define-syntax raise
122
+ (syntax-rules ()
123
+ ((raise)
124
+ (error "raise requires (raise exception message [backtrace-str])"))
125
+ ((raise exc)
126
+ (%raise exc
127
+ (sprintf "%s:%s raised %s" (*FILE*) (*LINE*) exc)
128
+ (sprintf "%s:%s raised %s" (*FILE*) (*LINE*) exc)))
129
+ ((raise exc mes)
130
+ (%raise exc mes (sprintf "%s:%s raised %s" (*FILE*) (*LINE*) exc)))
131
+ ((raise exc mes backtrace)
132
+ (%raise exc mes backtrace))))
133
+
134
+
135
+ ;; guard for Exceptions
136
+ (define-syntax %guard-var
137
+ (syntax-rules (=> ...)
138
+ ((%guard-clause (var clauses ...))
139
+ var)))
140
+
141
+ (define-syntax %guard-clause
142
+ (syntax-rules (=> ...)
143
+ ((%guard-clause (var clauses ...))
144
+ (cond
145
+ clauses ...))))
146
+
147
+ (define-syntax guard
148
+ (syntax-rules ()
149
+ ((guard)
150
+ (error "guard requires (guard (var (clauses-like-cond)) body ...)"))
151
+ ((guard var-clauses)
152
+ (error "guard requires (guard (var (clauses-like-cond)) body ...)"))
153
+ ((guard var-clauses body ...)
154
+ (%guard
155
+ (%guard-var
156
+ var-clauses)
157
+ (%guard-clause
158
+ var-clauses)
159
+ body ...))))
160
+
161
+
162
+ ;; unwind-protect for Exceptions
163
+ (define-syntax unwind-protect
164
+ (syntax-rules ()
165
+ ((unwind-protect)
166
+ (error "unwind-protect requires (unwind-protect body cleanup) form."))
167
+ ((unwind-protect body)
168
+ (error "unwind-protect requires (unwind-protect body cleanup) form."))
169
+ ((unwind-protect body cleanup)
170
+ (let1 temp #f
171
+ (guard
172
+ (exc (#t (begin cleanup
173
+ temp)))
174
+ (begin0
175
+ (set! temp body)
176
+ cleanup))))))
177
+
178
+