ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/microscheme/init.scm
Revision: 1.17
Committed: Tue Dec 1 02:42:35 2015 UTC (8 years, 6 months ago) by root
Branch: MAIN
Changes since 1.16: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 ; Initialization file for TinySCHEME 1.41
2
3 (gc-verbose #t)
4
5 ;;;; Utility to ease macro creation
6 (define (macro-expand form)
7 ((eval (get-closure-code (eval (car form)))) form))
8
9 (define (macro-expand-all form)
10 (if (macro? form)
11 (macro-expand-all (macro-expand form))
12 form))
13
14 (define *compile-hook* macro-expand-all)
15
16
17 (macro (unless form)
18 `(if (not ,(cadr form)) (begin ,@(cddr form))))
19
20 (macro (when form)
21 `(if ,(cadr form) (begin ,@(cddr form))))
22
23 ; DEFINE-MACRO Contributed by Andy Gaynor
24 (macro (define-macro dform)
25 (if (symbol? (cadr dform))
26 `(macro ,@(cdr dform))
27 (let ((form (gensym)))
28 `(macro (,(caadr dform) ,form)
29 (apply (lambda ,(cdadr dform) ,@(cddr dform)) (cdr ,form))))))
30
31 ; Utilities for math. Notice that inexact->exact is primitive,
32 ; but exact->inexact is not.
33 (define exact? integer?)
34 (define exact-integer? integer?)
35 (define (inexact? x) (and (real? x) (not (integer? x))))
36 (define (even? n) (= (remainder n 2) 0))
37 (define (odd? n) (not (= (remainder n 2) 0)))
38 (define (zero? n) (= n 0))
39 (define (positive? n) (> n 0))
40 (define (negative? n) (< n 0))
41 (define complex? number?)
42 (define rational? real?)
43 (define (abs n) (if (>= n 0) n (- n)))
44 (define (exact->inexact n) (* n 1.0))
45 (define (<> n1 n2) (not (= n1 n2)))
46 ;; missing: numerator/denominator
47
48 ; min and max must return inexact if any arg is inexact
49 (define (max . lst)
50 (foldr (lambda (a b)
51 (if (> a b)
52 (if (exact? b) a (exact->inexact a))
53 (if (exact? a) b (exact->inexact b))))
54 (car lst) (cdr lst)))
55 (define (min . lst)
56 (foldr (lambda (a b)
57 (if (< a b)
58 (if (exact? b) a (exact->inexact a))
59 (if (exact? a) b (exact->inexact b))))
60 (car lst) (cdr lst)))
61
62 (define (succ x) (+ x 1))
63 (define (pred x) (- x 1))
64 (define gcd
65 (lambda a
66 (if (null? a)
67 0
68 (let ((aa (abs (car a)))
69 (bb (abs (cadr a))))
70 (if (= bb 0)
71 aa
72 (gcd bb (remainder aa bb)))))))
73 (define lcm
74 (lambda a
75 (if (null? a)
76 1
77 (let ((aa (abs (car a)))
78 (bb (abs (cadr a))))
79 (if (or (= aa 0) (= bb 0))
80 0
81 (abs (* (quotient aa (gcd aa bb)) bb)))))))
82
83
84 (define (string . charlist)
85 (list->string charlist))
86
87 (define (list->string charlist)
88 (let* ((len (length charlist))
89 (newstr (make-string len))
90 (fill-string!
91 (lambda (str i len charlist)
92 (if (= i len)
93 str
94 (begin (string-set! str i (car charlist))
95 (fill-string! str (+ i 1) len (cdr charlist)))))))
96 (fill-string! newstr 0 len charlist)))
97
98 (define (string-fill! s e)
99 (let ((n (string-length s)))
100 (let loop ((i 0))
101 (if (= i n)
102 s
103 (begin (string-set! s i e) (loop (succ i)))))))
104
105 (define (string->list s)
106 (let loop ((n (pred (string-length s))) (l '()))
107 (if (= n -1)
108 l
109 (loop (pred n) (cons (string-ref s n) l)))))
110
111 (define (string-copy str)
112 (string-append str))
113
114 (define (string->anyatom str pred)
115 (let* ((a (string->atom str)))
116 (if (pred a) a
117 (error "string->xxx: not a xxx" a))))
118
119 (define (string->number str . base)
120 (let ((n (string->atom str (if (null? base) 10 (car base)))))
121 (if (number? n) n #f)))
122
123 (define (anyatom->string n pred)
124 (if (pred n)
125 (atom->string n)
126 (error "xxx->string: not a xxx" n)))
127
128 (define (number->string n . base)
129 (atom->string n (if (null? base) 10 (car base))))
130
131
132 (define (char-cmp? cmp a b)
133 (cmp (char->integer a) (char->integer b)))
134 (define (char-ci-cmp? cmp a b)
135 (cmp (char->integer (char-downcase a)) (char->integer (char-downcase b))))
136
137 (define (char=? a b) (char-cmp? = a b))
138 (define (char<? a b) (char-cmp? < a b))
139 (define (char>? a b) (char-cmp? > a b))
140 (define (char<=? a b) (char-cmp? <= a b))
141 (define (char>=? a b) (char-cmp? >= a b))
142
143 (define (char-ci=? a b) (char-ci-cmp? = a b))
144 (define (char-ci<? a b) (char-ci-cmp? < a b))
145 (define (char-ci>? a b) (char-ci-cmp? > a b))
146 (define (char-ci<=? a b) (char-ci-cmp? <= a b))
147 (define (char-ci>=? a b) (char-ci-cmp? >= a b))
148
149 ; Note the trick of returning (cmp x y)
150 (define (string-cmp? chcmp cmp a b)
151 (let ((na (string-length a)) (nb (string-length b)))
152 (let loop ((i 0))
153 (cond
154 ((= i na)
155 (if (= i nb) (cmp 0 0) (cmp 0 1)))
156 ((= i nb)
157 (cmp 1 0))
158 ((chcmp = (string-ref a i) (string-ref b i))
159 (loop (succ i)))
160 (else
161 (chcmp cmp (string-ref a i) (string-ref b i)))))))
162
163
164 (define (string=? a b) (string-cmp? char-cmp? = a b))
165 (define (string<? a b) (string-cmp? char-cmp? < a b))
166 (define (string>? a b) (string-cmp? char-cmp? > a b))
167 (define (string<=? a b) (string-cmp? char-cmp? <= a b))
168 (define (string>=? a b) (string-cmp? char-cmp? >= a b))
169
170 (define (string-ci=? a b) (string-cmp? char-ci-cmp? = a b))
171 (define (string-ci<? a b) (string-cmp? char-ci-cmp? < a b))
172 (define (string-ci>? a b) (string-cmp? char-ci-cmp? > a b))
173 (define (string-ci<=? a b) (string-cmp? char-ci-cmp? <= a b))
174 (define (string-ci>=? a b) (string-cmp? char-ci-cmp? >= a b))
175
176 (define (list . x) x)
177
178 (define (foldr f x lst)
179 (if (null? lst)
180 x
181 (foldr f (f x (car lst)) (cdr lst))))
182
183 (define (unzip1-with-cdr . lists)
184 (unzip1-with-cdr-iterative lists '() '()))
185
186 (define (unzip1-with-cdr-iterative lists cars cdrs)
187 (if (null? lists)
188 (cons cars cdrs)
189 (let ((car1 (caar lists))
190 (cdr1 (cdar lists)))
191 (unzip1-with-cdr-iterative
192 (cdr lists)
193 (append cars (list car1))
194 (append cdrs (list cdr1))))))
195
196 (define (map proc . lists)
197 (if (null? lists)
198 (apply proc)
199 (if (null? (car lists))
200 '()
201 (let* ((unz (apply unzip1-with-cdr lists))
202 (cars (car unz))
203 (cdrs (cdr unz)))
204 (cons (apply proc cars) (apply map (cons proc cdrs)))))))
205
206 (define (for-each proc . lists)
207 (if (null? lists)
208 (apply proc)
209 (if (null? (car lists))
210 #t
211 (let* ((unz (apply unzip1-with-cdr lists))
212 (cars (car unz))
213 (cdrs (cdr unz)))
214 (apply proc cars) (apply map (cons proc cdrs))))))
215
216 (define (list-tail x k)
217 (if (zero? k)
218 x
219 (list-tail (cdr x) (- k 1))))
220
221 (define (list-ref x k)
222 (car (list-tail x k)))
223
224 (define (last-pair x)
225 (if (pair? (cdr x))
226 (last-pair (cdr x))
227 x))
228
229 (define (head stream) (car stream))
230
231 (define (tail stream) (force (cdr stream)))
232
233 (define (vector-equal? x y)
234 (and (vector? x) (vector? y) (= (vector-length x) (vector-length y))
235 (let ((n (vector-length x)))
236 (let loop ((i 0))
237 (if (= i n)
238 #t
239 (and (equal? (vector-ref x i) (vector-ref y i))
240 (loop (succ i))))))))
241
242 (define (list->vector x)
243 (apply vector x))
244
245 (define (vector-fill! v e)
246 (let ((n (vector-length v)))
247 (let loop ((i 0))
248 (if (= i n)
249 v
250 (begin (vector-set! v i e) (loop (succ i)))))))
251
252 (define (vector->list v)
253 (let loop ((n (pred (vector-length v))) (l '()))
254 (if (= n -1)
255 l
256 (loop (pred n) (cons (vector-ref v n) l)))))
257
258 ;; The following quasiquote macro is due to Eric S. Tiedemann.
259 ;; Copyright 1988 by Eric S. Tiedemann; all rights reserved.
260 ;;
261 ;; Subsequently modified to handle vectors: D. Souflis
262
263 (macro
264 quasiquote
265 (lambda (l)
266 (define (mcons f l r)
267 (if (and (pair? r)
268 (eq? (car r) 'quote)
269 (eq? (car (cdr r)) (cdr f))
270 (pair? l)
271 (eq? (car l) 'quote)
272 (eq? (car (cdr l)) (car f)))
273 (if (or (procedure? f) (number? f) (string? f))
274 f
275 (list 'quote f))
276 (if (eqv? l vector)
277 (apply l (eval r))
278 (list 'cons l r)
279 )))
280 (define (mappend f l r)
281 (if (or (null? (cdr f))
282 (and (pair? r)
283 (eq? (car r) 'quote)
284 (eq? (car (cdr r)) '())))
285 l
286 (list 'append l r)))
287 (define (foo level form)
288 (cond ((not (pair? form))
289 (if (or (procedure? form) (number? form) (string? form))
290 form
291 (list 'quote form))
292 )
293 ((eq? 'quasiquote (car form))
294 (mcons form ''quasiquote (foo (+ level 1) (cdr form))))
295 (#t (if (zero? level)
296 (cond ((eq? (car form) 'unquote) (car (cdr form)))
297 ((eq? (car form) 'unquote-splicing)
298 (error "Unquote-splicing wasn't in a list:"
299 form))
300 ((and (pair? (car form))
301 (eq? (car (car form)) 'unquote-splicing))
302 (mappend form (car (cdr (car form)))
303 (foo level (cdr form))))
304 (#t (mcons form (foo level (car form))
305 (foo level (cdr form)))))
306 (cond ((eq? (car form) 'unquote)
307 (mcons form ''unquote (foo (- level 1)
308 (cdr form))))
309 ((eq? (car form) 'unquote-splicing)
310 (mcons form ''unquote-splicing
311 (foo (- level 1) (cdr form))))
312 (#t (mcons form (foo level (car form))
313 (foo level (cdr form)))))))))
314 (foo 0 (car (cdr l)))))
315
316 ;;;;;Helper for the dynamic-wind definition. By Tom Breton (Tehom)
317 (define (shared-tail x y)
318 (let ((len-x (length x))
319 (len-y (length y)))
320 (define (shared-tail-helper x y)
321 (if
322 (eq? x y)
323 x
324 (shared-tail-helper (cdr x) (cdr y))))
325
326 (cond
327 ((> len-x len-y)
328 (shared-tail-helper
329 (list-tail x (- len-x len-y))
330 y))
331 ((< len-x len-y)
332 (shared-tail-helper
333 x
334 (list-tail y (- len-y len-x))))
335 (#t (shared-tail-helper x y)))))
336
337 ;;;;;Dynamic-wind by Tom Breton (Tehom)
338
339 ;;Guarded because we must only eval this once, because doing so
340 ;;redefines call/cc in terms of old call/cc
341 (unless (defined? 'dynamic-wind)
342 (let
343 ;;These functions are defined in the context of a private list of
344 ;;pairs of before/after procs.
345 ( (*active-windings* '())
346 ;;We'll define some functions into the larger environment, so
347 ;;we need to know it.
348 (outer-env (current-environment)))
349
350 ;;Poor-man's structure operations
351 (define before-func car)
352 (define after-func cdr)
353 (define make-winding cons)
354
355 ;;Manage active windings
356 (define (activate-winding! new)
357 ((before-func new))
358 (set! *active-windings* (cons new *active-windings*)))
359 (define (deactivate-top-winding!)
360 (let ((old-top (car *active-windings*)))
361 ;;Remove it from the list first so it's not active during its
362 ;;own exit.
363 (set! *active-windings* (cdr *active-windings*))
364 ((after-func old-top))))
365
366 (define (set-active-windings! new-ws)
367 (unless (eq? new-ws *active-windings*)
368 (let ((shared (shared-tail new-ws *active-windings*)))
369
370 ;;Define the looping functions.
371 ;;Exit the old list. Do deeper ones last. Don't do
372 ;;any shared ones.
373 (define (pop-many)
374 (unless (eq? *active-windings* shared)
375 (deactivate-top-winding!)
376 (pop-many)))
377 ;;Enter the new list. Do deeper ones first so that the
378 ;;deeper windings will already be active. Don't do any
379 ;;shared ones.
380 (define (push-many new-ws)
381 (unless (eq? new-ws shared)
382 (push-many (cdr new-ws))
383 (activate-winding! (car new-ws))))
384
385 ;;Do it.
386 (pop-many)
387 (push-many new-ws))))
388
389 ;;The definitions themselves.
390 (eval
391 `(define call-with-current-continuation
392 ;;It internally uses the built-in call/cc, so capture it.
393 ,(let ((old-c/cc call-with-current-continuation))
394 (lambda (func)
395 ;;Use old call/cc to get the continuation.
396 (old-c/cc
397 (lambda (continuation)
398 ;;Call func with not the continuation itself
399 ;;but a procedure that adjusts the active
400 ;;windings to what they were when we made
401 ;;this, and only then calls the
402 ;;continuation.
403 (func
404 (let ((current-ws *active-windings*))
405 (lambda (x)
406 (set-active-windings! current-ws)
407 (continuation x)))))))))
408 outer-env)
409 ;;We can't just say "define (dynamic-wind before thunk after)"
410 ;;because the lambda it's defined to lives in this environment,
411 ;;not in the global environment.
412 (eval
413 `(define dynamic-wind
414 ,(lambda (before thunk after)
415 ;;Make a new winding
416 (activate-winding! (make-winding before after))
417 (let ((result (thunk)))
418 ;;Get rid of the new winding.
419 (deactivate-top-winding!)
420 ;;The return value is that of thunk.
421 result)))
422 outer-env)))
423
424 (define call/cc call-with-current-continuation)
425
426
427 ;;;;; atom? and equal? written by a.k
428
429 ;;;; atom?
430 (define (atom? x)
431 (not (pair? x)))
432
433 ;;;; equal?
434 (define (equal? x y)
435 (cond
436 ((pair? x)
437 (and (pair? y)
438 (equal? (car x) (car y))
439 (equal? (cdr x) (cdr y))))
440 ((vector? x)
441 (and (vector? y) (vector-equal? x y)))
442 ((string? x)
443 (and (string? y) (string=? x y)))
444 (else (eqv? x y))))
445
446 ;;;; (do ((var init inc) ...) (endtest result ...) body ...)
447 ;;
448 (macro do
449 (lambda (do-macro)
450 (apply (lambda (do vars endtest . body)
451 (let ((do-loop (gensym)))
452 `(letrec ((,do-loop
453 (lambda ,(map (lambda (x)
454 (if (pair? x) (car x) x))
455 `,vars)
456 (if ,(car endtest)
457 (begin ,@(cdr endtest))
458 (begin
459 ,@body
460 (,do-loop
461 ,@(map (lambda (x)
462 (cond
463 ((not (pair? x)) x)
464 ((< (length x) 3) (car x))
465 (else (car (cdr (cdr x))))))
466 `,vars)))))))
467 (,do-loop
468 ,@(map (lambda (x)
469 (if (and (pair? x) (cdr x))
470 (car (cdr x))
471 '()))
472 `,vars)))))
473 do-macro)))
474
475 ;;;; generic-member
476 (define (generic-member cmp obj lst)
477 (cond
478 ((null? lst) #f)
479 ((cmp obj (car lst)) lst)
480 (else (generic-member cmp obj (cdr lst)))))
481
482 (define (memq obj lst)
483 (generic-member eq? obj lst))
484 (define (memv obj lst)
485 (generic-member eqv? obj lst))
486 (define (member obj lst)
487 (generic-member equal? obj lst))
488
489 ;;;; generic-assoc
490 (define (generic-assoc cmp obj alst)
491 (cond
492 ((null? alst) #f)
493 ((cmp obj (caar alst)) (car alst))
494 (else (generic-assoc cmp obj (cdr alst)))))
495
496 (define (assq obj alst)
497 (generic-assoc eq? obj alst))
498 (define (assv obj alst)
499 (generic-assoc eqv? obj alst))
500 (define (assoc obj alst)
501 (generic-assoc equal? obj alst))
502
503 (define (acons x y z) (cons (cons x y) z))
504
505 ;;;; Handy for imperative programs
506 ;;;; Used as: (define-with-return (foo x y) .... (return z) ...)
507 (macro (define-with-return form)
508 `(define ,(cadr form)
509 (call/cc (lambda (return) ,@(cddr form)))))
510
511 ;;;; Simple exception handling
512 ;
513 ; Exceptions are caught as follows:
514 ;
515 ; (catch (do-something to-recover and-return meaningful-value)
516 ; (if-something goes-wrong)
517 ; (with-these calls))
518 ;
519 ; "Catch" establishes a scope spanning multiple call-frames
520 ; until another "catch" is encountered.
521 ;
522 ; Exceptions are thrown with:
523 ;
524 ; (throw "message")
525 ;
526 ; If used outside a (catch ...), reverts to (error "message)
527
528 (define *handlers* (list))
529
530 (define (push-handler proc)
531 (set! *handlers* (cons proc *handlers*)))
532
533 (define (pop-handler)
534 (let ((h (car *handlers*)))
535 (set! *handlers* (cdr *handlers*))
536 h))
537
538 (define (more-handlers?)
539 (pair? *handlers*))
540
541 (define (throw . x)
542 (if (more-handlers?)
543 (apply (pop-handler))
544 (apply error x)))
545
546 (macro (catch form)
547 (let ((label (gensym)))
548 `(call/cc (lambda (exit)
549 (push-handler (lambda () (exit ,(cadr form))))
550 (let ((,label (begin ,@(cddr form))))
551 (pop-handler)
552 ,label)))))
553
554 (define *error-hook* throw)
555
556
557 ;;;;; Definition of MAKE-ENVIRONMENT, to be used with two-argument EVAL
558
559 (macro (make-environment form)
560 `(apply (lambda ()
561 ,@(cdr form)
562 (current-environment))))
563
564 (define-macro (eval-polymorphic x . envl)
565 (display envl)
566 (let* ((env (if (null? envl) (current-environment) (eval (car envl))))
567 (xval (eval x env)))
568 (if (closure? xval)
569 (make-closure (get-closure-code xval) env)
570 xval)))
571
572 ; Redefine this if you install another package infrastructure
573 ; Also redefine 'package'
574 (define *colon-hook* eval)
575
576 ;;;;; I/O
577
578 (define (input-output-port? p)
579 (and (input-port? p) (output-port? p)))
580
581 (define (close-port p)
582 (cond
583 ((input-output-port? p) (close-input-port (close-output-port p)))
584 ((input-port? p) (close-input-port p))
585 ((output-port? p) (close-output-port p))
586 (else (throw "Not a port" p))))
587
588 (define (call-with-input-file s p)
589 (let ((inport (open-input-file s)))
590 (if (eq? inport #f)
591 #f
592 (let ((res (p inport)))
593 (close-input-port inport)
594 res))))
595
596 (define (call-with-output-file s p)
597 (let ((outport (open-output-file s)))
598 (if (eq? outport #f)
599 #f
600 (let ((res (p outport)))
601 (close-output-port outport)
602 res))))
603
604 (define (with-input-from-file s p)
605 (let ((inport (open-input-file s)))
606 (if (eq? inport #f)
607 #f
608 (let ((prev-inport (current-input-port)))
609 (set-input-port inport)
610 (let ((res (p)))
611 (close-input-port inport)
612 (set-input-port prev-inport)
613 res)))))
614
615 (define (with-output-to-file s p)
616 (let ((outport (open-output-file s)))
617 (if (eq? outport #f)
618 #f
619 (let ((prev-outport (current-output-port)))
620 (set-output-port outport)
621 (let ((res (p)))
622 (close-output-port outport)
623 (set-output-port prev-outport)
624 res)))))
625
626 (define (with-input-output-from-to-files si so p)
627 (let ((inport (open-input-file si))
628 (outport (open-input-file so)))
629 (if (not (and inport outport))
630 (begin
631 (close-input-port inport)
632 (close-output-port outport)
633 #f)
634 (let ((prev-inport (current-input-port))
635 (prev-outport (current-output-port)))
636 (set-input-port inport)
637 (set-output-port outport)
638 (let ((res (p)))
639 (close-input-port inport)
640 (close-output-port outport)
641 (set-input-port prev-inport)
642 (set-output-port prev-outport)
643 res)))))
644
645 ; Random number generator (maximum cycle)
646 (define *seed* 1)
647 (define (random-next)
648 (let* ((a 16807) (m 2147483647) (q (quotient m a)) (r (modulo m a)))
649 (set! *seed*
650 (- (* a (- *seed*
651 (* (quotient *seed* q) q)))
652 (* (quotient *seed* q) r)))
653 (if (< *seed* 0) (set! *seed* (+ *seed* m)))
654 *seed*))
655
656 ;; SRFI-0
657 ;; COND-EXPAND
658 ;; Implemented as a macro
659 (define *features* '(srfi-0))
660
661 (define-macro (cond-expand . cond-action-list)
662 (cond-expand-runtime cond-action-list))
663
664 (define (cond-expand-runtime cond-action-list)
665 (if (null? cond-action-list)
666 #t
667 (if (cond-eval (caar cond-action-list))
668 `(begin ,@(cdar cond-action-list))
669 (cond-expand-runtime (cdr cond-action-list)))))
670
671 (define (cond-eval-and cond-list)
672 (foldr (lambda (x y) (and (cond-eval x) (cond-eval y))) #t cond-list))
673
674 (define (cond-eval-or cond-list)
675 (foldr (lambda (x y) (or (cond-eval x) (cond-eval y))) #f cond-list))
676
677 (define (cond-eval condition)
678 (cond
679 ((symbol? condition)
680 (if (member condition *features*) #t #f))
681 ((eq? condition #t) #t)
682 ((eq? condition #f) #f)
683 (else (case (car condition)
684 ((and) (cond-eval-and (cdr condition)))
685 ((or) (cond-eval-or (cdr condition)))
686 ((not) (if (not (null? (cddr condition)))
687 (error "cond-expand : 'not' takes 1 argument")
688 (not (cond-eval (cadr condition)))))
689 (else (error "cond-expand : unknown operator" (car condition)))))))
690
691 ; compatibility functions added by schmorp@schmorp.de
692 (macro (defmacro dform)
693 (let ((name (cadr dform)) (formals (caddr dform)) (body (cdddr dform)))
694 `(define-macro (,name . ,formals) ,@body)))
695
696 ;; simple syntax-rules
697
698 ;; values/call-with-values
699 (load "simple-syntax-rules/values.scm")
700 ;; (hash-)table
701 ;(load "simple-syntax-rules/table.scm")
702 ;; "the real stuff"
703 ;(load "simple-syntax-rules/usual.scm")
704 ;(load "simple-syntax-rules/rules.scm")
705 ;(load "simple-syntax-rules/memo.scm")
706 ;(load "simple-syntax-rules/syntax.scm")
707 ;(load "simple-syntax-rules/ev.scm")
708 ;(load "simple-syntax-rules/ex.scm")
709 ;(macro (define-syntax form) (expand form top-level-env))
710
711 ;(load "macros/expand.scm")
712 ;(load "macros/misc.scm")
713 ;(load "macros/prefs.scm")
714 ;(load "macros/syntaxenv.scm")
715 ;(load "macros/syntaxrules.scm")
716 ;(load "macros/usual.scm")
717
718 ;; r7rs
719 ; char library
720 ; string-upcase
721 ; string-downcase
722 ; string-foldcase
723 ; sring-map, vector-map, string-for-each, vector-for-each
724 ; bytevectors
725
726 ;; srfi-1
727
728 (define (check-arg pred val caller)
729 (let lp ((val val))
730 (if (pred val) val (lp (error "Bad argument" val pred caller)))))
731
732 ; Some macros and functions that the SRFI 1 reference implementation
733 ; requires that it does not define and are not part of R5RS.
734
735 (define-macro let-optionals
736 (lambda (input names . code)
737 (let ((input-left (gensym)))
738 `(let ((,input-left ,input))
739 ,(let next ((names names))
740 (if (null? names)
741 `(begin ,@code)
742 `(let ((,input-left (if (null? ,input-left)
743 '()
744 (cdr ,input-left)))
745 (,(caar names) (if (null? ,input-left)
746 ,(cadar names)
747 (car ,input-left))))
748 ,(next (cdr names)))))))))
749
750 (define-macro receive
751 (lambda (names values . code)
752 `(call-with-values (lambda () ,values)
753 (lambda ,names ,@code))))
754
755
756 (define (:optional data default)
757 (if (null? data)
758 default
759 (car data)))
760
761 (load "srfi-1.scm")
762
763 ;(load "srfi-55.scm")
764
765 ;(register-extension '(srfi 1) (lamba () (load "srfi-1.scm")))
766 ;(register-extension '(srfi 23) (lamba () ())) ; error builtin
767 ;(register-extension '(srfi 55) (lamba () ())) ; always available
768
769 ;; end of init
770
771 ;(load "test.scm")
772
773 (define $sc-put-cte #f)
774 (define sc-expand #f)
775 (define $make-environment #f)
776 ;(define environment? #f)
777 ;(define interaction-environment #f)
778 (define identifier? #f)
779 (define syntax->list #f)
780 (define syntax->vector #f)
781 (define syntax-object->datum #f)
782 (define datum->syntax-object #f)
783 (define generate-temporaries #f)
784 (define free-identifier=? #f)
785 (define bound-identifier=? #f)
786 (define literal-identifier=? #f)
787 (define syntax-error #f)
788 (define $syntax-dispatch #f)
789
790 (define void (lambda () (if #f #f)))
791
792 (define andmap
793 (lambda (f first . rest)
794 (or (null? first)
795 (if (null? rest)
796 (let andmap ((first first))
797 (let ((x (car first)) (first (cdr first)))
798 (if (null? first)
799 (f x)
800 (and (f x) (andmap first)))))
801 (let andmap ((first first) (rest rest))
802 (let ((x (car first))
803 (xr (map car rest))
804 (first (cdr first))
805 (rest (map cdr rest)))
806 (if (null? first)
807 (apply f (cons x xr))
808 (and (apply f (cons x xr)) (andmap first rest)))))))))
809
810 (define ormap
811 (lambda (proc list1)
812 (and (not (null? list1))
813 (or (proc (car list1)) (ormap proc (cdr list1))))))
814
815 (define *properties* '())
816
817 (define (putprop sym k v)
818 (set! *properties* (acons (list sym k) v *properties*)))
819
820 (define (remprop sym k)
821 (putprop sym k #f))
822
823 (define (getprop sym k)
824 (assoc (list sym k) *properties*))
825
826 (load "psyntax.pp")
827
828 ;(define *compile-hook* sc-expand)
829
830 (load "test.scm")
831
832 (gc-verbose #f)