ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/microscheme/init.scm
Revision: 1.21
Committed: Tue Dec 1 03:56:23 2015 UTC (10 years, 10 months ago) by root
Branch: MAIN
Changes since 1.20: +4 -0 lines
Log Message:
more r7rs

File Contents

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