Talked to Stallman. Actually, the syntax-case copyright is no
[bpt/guile.git] / ice-9 / slib.scm
CommitLineData
0f2d19dd 1;;; installed-scm-file
8bb7330c 2(define-module (ice-9 slib))
0f2d19dd
JB
3
4\f
5
6(define (eval-load <filename> evl)
7 (if (not (file-exists? <filename>))
8 (set! <filename> (string-append <filename> (scheme-file-suffix))))
9 (call-with-input-file <filename>
10 (lambda (port)
11 (let ((old-load-pathname *load-pathname*))
12 (set! *load-pathname* <filename>)
75a97b92 13 (do ((o (read port) (read port)))
0f2d19dd
JB
14 ((eof-object? o))
15 (evl o))
16 (set! *load-pathname* old-load-pathname)))))
17
18\f
19
20(define slib:exit quit)
21(define slib:error error)
7ed9feb0 22(define slib:warn warn)
841d28d7 23(define slib:eval (lambda (x) (eval-in-module x slib-module)))
0f2d19dd
JB
24(define defmacro:eval eval)
25(define logical:logand logand)
26(define logical:logior logior)
27(define logical:logxor logxor)
28(define logical:lognot lognot)
29(define logical:ash ash)
30(define logical:logcount logcount)
31(define logical:integer-length integer-length)
32(define logical:bit-extract bit-extract)
33(define logical:integer-expt integer-expt)
34(define logical:ipow-by-squaring ipow-by-squaring)
35(define slib:eval-load eval-load)
36(define slib:tab #\tab)
37(define slib:form-feed #\page)
38
ed218d98
MV
39(define slib-module (current-module))
40
41(define (defined? symbol)
42 (module-defined? slib-module symbol))
43
0f2d19dd
JB
44(define slib:features
45 (append '(source
46 eval
47 abort
48 alist
49 defmacro
50 delay
51 dynamic-wind
52 full-continuation
53 hash
54 hash-table
55 line-i/o
56 logical
57 multiarg/and-
58 multiarg-apply
59 promise
60 rev2-procedures
61 rev4-optional-procedures
62 string-port
63 with-file)
64
b1818df3 65 (if (defined? 'getenv)
0f2d19dd
JB
66 '(getenv)
67 '())
68
b1818df3 69 (if (defined? 'current-time)
0f2d19dd
JB
70 '(current-time)
71 '())
72
b1818df3 73 (if (defined? 'system)
0f2d19dd
JB
74 '(system)
75 '())
76
b1818df3 77 (if (defined? 'array?)
0f2d19dd
JB
78 '(array)
79 '())
80
b1818df3 81 (if (defined? 'char-ready?)
0f2d19dd
JB
82 '(char-ready?)
83 '())
84
b1818df3 85 (if (defined? 'array-for-each)
0f2d19dd
JB
86 '(array-for-each)
87 '())
88
89 (if (and (string->number "0.0") (inexact? (string->number "0.0")))
90 '(inexact)
91 '())
92
93 (if (rational? (string->number "1/19"))
94 '(rational)
95 '())
96
97 (if (real? (string->number "0.0"))
98 '(real)
99 ())
100
101 (if (complex? (string->number "1+i"))
102 '(complex)
103 '())
104
105 (let ((n (string->number "9999999999999999999999999999999")))
106 (if (and n (exact? n))
107 '(bignum)
108 '()))))
109
110
9b345f6c 111;;; FIXME: Because uers want require to search the path, this uses
096d5f90 112;;; load-from-path, which probably isn't a hot idea. slib
9b345f6c
JB
113;;; doesn't expect this function to search a path, so I expect to get
114;;; bug reports at some point complaining that the wrong file gets
115;;; loaded when something accidentally appears in the path before
116;;; slib, etc. ad nauseum. However, the right fix seems to involve
117;;; changing catalog:get in slib/require.scm, and I don't expect
118;;; Aubrey will integrate such a change. So I'm just going to punt
119;;; for the time being.
534a0099 120(define-public (slib:load name)
0f2d19dd
JB
121 (save-module-excursion
122 (lambda ()
123 (set-current-module slib-module)
d1005e3c
MD
124 (let ((errinfo (catch 'system-error
125 (lambda ()
126 (load-from-path name)
127 #f)
128 (lambda args args))))
129 (if (and errinfo
130 (catch 'system-error
131 (lambda ()
132 (load-from-path
133 (string-append name ".scm"))
134 #f)
135 (lambda args args)))
c51bfd81 136 (apply throw errinfo))))))
0f2d19dd
JB
137
138(define slib:load-source slib:load)
139(define defmacro:load slib:load)
140
c51bfd81
MD
141(define slib-parent-dir
142 (let* ((path (%search-load-path "slib/require.scm")))
00f06035
GH
143 (if path
144 (make-shared-substring path 0 (- (string-length path) 17))
145 (error "Could not find slib/require.scm in " %load-path))))
c51bfd81
MD
146
147(define-public (implementation-vicinity)
148 (string-append slib-parent-dir "/"))
149(define (library-vicinity)
150 (string-append (implementation-vicinity) "slib/"))
ad76c8d9
TP
151(define home-vicinity
152 (let ((home-path (getenv "HOME")))
153 (lambda () home-path)))
0f2d19dd
JB
154(define (scheme-implementation-type) 'guile)
155(define (scheme-implementation-version) "")
156
157(define (output-port-width . arg) 80)
158(define (output-port-height . arg) 24)
841d28d7 159(define (identity x) x)
4b0d6055 160
0f2d19dd
JB
161;;; {Time}
162;;;
163
164(define difftime -)
165(define offset-time +)
166
167\f
168(define %system-define define)
169
170(define define
171 (procedure->memoizing-macro
172 (lambda (exp env)
173 (if (= (length env) 1)
174 `(define-public ,@(cdr exp))
175 `(%system-define ,@(cdr exp))))))
176
7a0ff2f8
MD
177;;; Hack to make syncase macros work in the slib module
178(if (nested-ref the-root-module '(app modules ice-9 syncase))
179 (set-object-property! (module-local-variable (current-module) 'define)
180 '*sc-expander*
181 '(define)))
182
0f2d19dd
JB
183(define (software-type) 'UNIX)
184
c51bfd81 185(slib:load (in-vicinity (library-vicinity) "require.scm"))
0f2d19dd
JB
186
187(define-public require require:require)
c51bfd81
MD
188
189;; {Extensions to the require system so that the user can add new
190;; require modules easily.}
191
192(define *vicinity-table*
193 (list
194 (cons 'implementation (implementation-vicinity))
195 (cons 'library (library-vicinity))))
196
197(define (install-require-vicinity name vicinity)
198 (let ((entry (assq name *vicinity-table*)))
199 (if entry
200 (set-cdr! entry vicinity)
201 (set! *vicinity-table*
202 (acons name vicinity *vicinity-table*)))))
203
204(define (install-require-module name vicinity-name file-name)
4d0d7ef9
MD
205 (if (not *catalog*) ;Fix which loads catalog in
206 (require:provided? 'random)) ;slib2b2
c51bfd81
MD
207 (let ((entry (assq name *catalog*))
208 (vicinity (cdr (assq vicinity-name *vicinity-table*))))
209 (let ((path-name (in-vicinity vicinity file-name)))
210 (if entry
211 (set-cdr! entry path-name)
212 (set! *catalog*
213 (acons name path-name *catalog*))))))