|
35 | 35 | |#
|
36 | 36 |
|
37 | 37 | (define-library (scheme r4rs)
|
38 |
| - (import (only (meevax boolean) boolean? not) |
| 38 | + (import (only (meevax apply) apply) |
| 39 | + (only (meevax boolean) boolean? not) |
39 | 40 | (only (meevax character) char? char=? char<? char>? char<=? char>=? char-ci=? char-ci<? char-ci>? char-ci<=? char-ci>=? char-alphabetic? char-numeric? char-whitespace? char-upper-case? char-lower-case? char->integer integer->char char-upcase char-downcase)
|
40 | 41 | (only (meevax comparator) eq? eqv? equal?)
|
41 | 42 | (only (meevax complex) make-rectangular make-polar real-part imag-part magnitude angle)
|
|
44 | 45 | (only (meevax inexact) exp log sqrt sin cos tan asin acos atan)
|
45 | 46 | (only (meevax list) null? list? list length append reverse list-tail list-ref memq memv assq assv)
|
46 | 47 | (only (meevax macro-transformer) er-macro-transformer identifier?)
|
| 48 | + (only (meevax map) map) |
47 | 49 | (only (meevax number) number? complex? real? rational? integer? exact? inexact? = < > <= >= zero? positive? negative? odd? even? max min + * - / abs quotient remainder modulo gcd lcm numerator denominator floor ceiling truncate round expt exact inexact number->string string->number)
|
48 | 50 | (only (meevax pair) pair? cons car cdr set-car! set-cdr! caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr)
|
49 | 51 | (only (meevax port) input-port? output-port? standard-input-port standard-output-port open-input-file open-output-file close eof-object?)
|
50 | 52 | (only (meevax procedure) procedure?)
|
51 | 53 | (only (meevax string) string? make-string string string-length string-ref string-set! string=? string<? string>? string<=? string>=? string-ci=? string-ci<? string-ci>? string-ci<=? string-ci>=? string-append string->list list->string string-copy string-fill!)
|
52 | 54 | (only (meevax symbol) symbol? symbol->string string->symbol)
|
53 | 55 | (only (meevax vector) vector? make-vector vector vector-length vector-ref vector-set! vector->list list->vector vector-fill!)
|
54 |
| - (prefix (only (meevax environment) load) %) |
55 | 56 | (prefix (meevax read) %)
|
56 | 57 | (prefix (meevax write) %)
|
| 58 | + (prefix (only (meevax environment) load) %) |
| 59 | + (only (srfi 39) make-parameter parameterize) |
57 | 60 | (only (srfi 45) delay force))
|
58 | 61 |
|
59 | 62 | (export quote lambda if set! cond case and or let let* letrec begin do delay
|
|
183 | 186 | (else x)))
|
184 | 187 | (expand (cadr form) 0))))
|
185 | 188 |
|
186 |
| - (define (every f xs) |
187 |
| - (if (pair? xs) |
188 |
| - (and (f (car xs)) |
189 |
| - (every f (cdr xs))) |
190 |
| - #t)) |
191 |
| - |
192 |
| - (define (map f x . xs) ; Chibi-Scheme |
193 |
| - (define (map f x a) |
194 |
| - (if (pair? x) |
195 |
| - (map f |
196 |
| - (cdr x) |
197 |
| - (cons (f (car x)) a)) |
198 |
| - (reverse a))) |
199 |
| - (define (map* f xs a) |
200 |
| - (if (every pair? xs) |
201 |
| - (map* f |
202 |
| - (map cdr xs '()) |
203 |
| - (cons (apply f (map car xs '())) a)) |
204 |
| - (reverse a))) |
205 |
| - (if (null? xs) |
206 |
| - (map f x '()) |
207 |
| - (map* f (cons x xs) '()))) |
208 |
| - |
209 |
| - (define (apply f x . xs) ; Chibi-Scheme |
210 |
| - (letrec ((apply (lambda (f xs) |
211 |
| - (f . xs)))) |
212 |
| - (if (null? xs) |
213 |
| - (apply f x) |
214 |
| - ((lambda (xs) |
215 |
| - (apply f (append (reverse (cdr xs)) |
216 |
| - (car xs)))) |
217 |
| - (reverse (cons x xs)))))) |
218 |
| - |
219 | 189 | (define-syntax let ; Chibi-Scheme
|
220 | 190 | (er-macro-transformer
|
221 | 191 | (lambda (form rename compare)
|
|
310 | 280 | (else (+ 1 fx)))))
|
311 | 281 | (cond ((< y x)
|
312 | 282 | (simplest-rational y x))
|
313 |
| - ((not (< x y)) |
314 |
| - (if (rational? x) x (error x))) |
| 283 | + ((not (< x y)) x) |
315 | 284 | ((positive? x)
|
316 | 285 | (simplest-rational-internal x y))
|
317 | 286 | ((negative? x)
|
|
348 | 317 | result))
|
349 | 318 | (call-with-output-port (open-output-file path) f))
|
350 | 319 |
|
351 |
| - (define %current-input-port (standard-input-port)) |
352 |
| - |
353 |
| - (define (current-input-port) %current-input-port) |
354 |
| - |
355 |
| - (define %current-output-port (standard-output-port)) |
| 320 | + (define current-input-port |
| 321 | + (make-parameter (standard-input-port))) |
356 | 322 |
|
357 |
| - (define (current-output-port) %current-output-port) |
| 323 | + (define current-output-port |
| 324 | + (make-parameter (standard-output-port))) |
358 | 325 |
|
359 | 326 | (define (with-input-from-file path thunk)
|
360 |
| - (let ((previous-input-port (current-input-port))) |
361 |
| - (set! %current-input-port (open-input-file path)) |
362 |
| - (thunk) |
363 |
| - (set! %current-input-port previous-input-port))) |
| 327 | + (parameterize ((current-input-port (open-input-file path))) |
| 328 | + (let ((result (thunk))) |
| 329 | + (close-input-port (current-input-port)) |
| 330 | + result))) |
364 | 331 |
|
365 | 332 | (define (with-output-to-file path thunk)
|
366 |
| - (let ((previous-output-port (current-output-port))) |
367 |
| - (set! %current-output-port (open-output-file path)) |
368 |
| - (thunk) |
369 |
| - (set! %current-output-port previous-output-port))) |
| 333 | + (parameterize ((current-output-port (open-output-file path))) |
| 334 | + (let ((result (thunk))) |
| 335 | + (close-output-port (current-output-port)) |
| 336 | + result))) |
370 | 337 |
|
371 | 338 | (define close-input-port close)
|
372 | 339 |
|
|
0 commit comments