1 ;;; "t3.init" Initialization file for SLIB for T3.1. -*-scheme-*-
2 ;;; Authors: David Carlton, Stephen Bevan, F. Javier Thayer, and Aubrey Jaffer.
4 ;;; This code is in the public domain.
6 ;;; File has T syntax, and should be compiled in standard-env.
7 ;;; Compiled file has .so suffix.
8 ;;; File (or compiled version) should be loaded into scheme-env.
10 ;;; This is provided with ABSOLUTELY NO GUARANTEE.
13 (define (software-type) 'UNIX)
15 (define (scheme-implementation-type) 'T)
17 (define (scheme-implementation-version) "3.1")
19 ;;; (scheme-implementation-home-page) should return a (string) URI
20 ;;; (Uniform Resource Identifier) for this scheme implementation's home
21 ;;; page; or false if there isn't one.
23 (define (scheme-implementation-home-page)
24 "ftp://ftp.cs.indiana.edu:21/pub/scheme-repository/imp/t/README")
26 ;;; (implementation-vicinity) should be defined to be the pathname of
27 ;;; the directory where any auxillary files to your Scheme
28 ;;; implementation reside. It is settable.
30 (define implementation-vicinity
31 (make-simple-switch 'implementation-vicinity
32 (lambda (x) (or (string? x) (false? x)))
34 (set (implementation-vicinity) "/usr/local/lib/tsystem/")
36 ;;; (library-vicinity) should be defined to be the pathname of the
37 ;;; directory where files of Scheme library functions reside. It is settable.
39 (define library-vicinity
40 (make-simple-switch 'library-vicinity
41 (lambda (x) (or (string? x) (false? x)))
43 (set (library-vicinity) "/usr/local/lib/slib/")
44 ;;Obviously put your value here.
46 ;;; (home-vicinity) should return the vicinity of the user's HOME
47 ;;; directory, the directory which typically contains files which
48 ;;; customize a computer environment for a user.
50 (define (home-vicinity) #f)
52 ;;; *FEATURES* should be set to a list of symbols describing features
53 ;;; of this implementation. See Template.scm for the list of feature
58 source ;can load scheme source files
59 ;(slib:load-source "filename")
60 compiled ;can load compiled files
61 ;(slib:load-compiled "filename")
63 rev4-optional-procedures
78 trace ;has macros: TRACE and UNTRACE
83 (let ((primitive-substring (*value standard-env 'substring)))
84 (lambda (string start end)
85 (primitive-substring string start (max 0 (- end 1))))))
87 ; Modify substring as T's substring takes (start,count) instead of
90 (set (syntax-table-entry (env-syntax-table scheme-env) 'require) '#f)
92 ; Turn off the macro REQUIRE so that it can be rebound as a function
95 ; extend <, >, <= and >= so that they take more than two arguments.
98 (let ((primitive< (*value standard-env '<)))
99 (labels ((v (lambda (a b . rest)
102 (and (primitive< a b)
103 (apply v b (car rest) (cdr rest)))))))
107 (let ((primitive> (*value standard-env '>)))
108 (labels ((v (lambda (a b . rest)
111 (and (primitive> a b)
112 (apply v b (car rest) (cdr rest)))))))
116 (let ((primitive<= (*value standard-env '<=)))
117 (labels ((v (lambda (a b . rest)
120 (and (primitive<= a b)
121 (apply v b (car rest) (cdr rest)))))))
125 (let ((primitive>= (*value standard-env '>=)))
126 (labels ((v (lambda (a b . rest)
129 (and (primitive>= a b)
130 (apply v b (car rest) (cdr rest)))))))
134 (let ((primitive= (*value standard-env '=)))
135 (labels ((v (lambda (a b . rest)
138 (and (primitive= a b)
139 (apply v b (car rest) (cdr rest)))))))
143 (let ((prim (*value standard-env 'gcd)))
144 (labels ((v (lambda x
146 ((= (length x) 1) (car x))
147 ('#t (prim (car x) (apply v (cdr x))))))))
150 (define list? (*value standard-env 'proper-list?))
152 (define program-arguments command-line)
154 ;;; (OUTPUT-PORT-WIDTH <port>)
155 (define output-port-width
157 (if (null? x) (line-length (standard-input))
158 (line-length (car x)))))
160 ;;; (OUTPUT-PORT-HEIGHT <port>)
161 (define (output-port-height . arg) 24)
163 ;;; (CURRENT-ERROR-PORT)
164 (define current-error-port
165 (let ((port (current-output-port)))
168 ;;; (TMPNAM) makes a temporary file name.
171 (lambda () (set! cntr (+ 1 cntr))
172 (let ((tmp (string-append "slib_" (number->string cntr))))
173 (if (file-exists? tmp) (tmpnam) tmp)))))
175 (define delete-file file-delete)
177 ;;; "rationalize" adjunct procedures.
178 (define (find-ratio x e)
179 (let ((rat (rationalize x e)))
180 (list (numerator rat) (denominator rat))))
181 (define (find-ratio-between x y)
182 (find-ratio (/ (+ x y) 2) (/ (- x y) 2)))
184 ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
185 ;;; be returned by CHAR->INTEGER.
186 (define char-code-limit 256)
188 ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
189 ;;; T already has it.
192 (define (identity x) x)
194 ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
195 (define (slib:eval form) (eval form scheme-env))
197 ;;; If your implementation provides R4RS macros:
198 ;(define macro:eval slib:eval)
199 ;(define macro:load load)
202 (list (cons 'defmacro
203 (lambda (name parms . body)
204 `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
206 (define (defmacro? m) (and (assq m *defmacros*) #t))
208 (define (macroexpand-1 e)
209 (if (pair? e) (let ((a (car e)))
210 (cond ((symbol? a) (set! a (assq a *defmacros*))
211 (if a (apply (cdr a) (cdr e)) e))
215 (define (macroexpand e)
216 (if (pair? e) (let ((a (car e)))
218 (set! a (assq a *defmacros*))
219 (if a (macroexpand (apply (cdr a) (cdr e))) e))
224 (let ((*gensym-counter* -1))
226 (set! *gensym-counter* (+ *gensym-counter* 1))
228 (string-append "slib:G" (number->string *gensym-counter*))))))
230 (define base:eval slib:eval)
231 (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
232 (define (defmacro:expand* x)
233 (require 'defmacroexpand) (apply defmacro:expand* x '()))
235 (define (defmacro:load <pathname>)
236 (slib:eval-load <pathname> defmacro:eval))
238 (define (slib:eval-load <pathname> evl)
239 (if (not (file-exists? <pathname>))
240 (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
241 (call-with-input-file <pathname>
243 (let ((old-load-pathname *load-pathname*))
244 (set! *load-pathname* <pathname>)
245 (do ((o (read port) (read port)))
248 (set! *load-pathname* old-load-pathname)))))
252 (let ((cep (current-error-port)))
253 (if (provided? 'trace) (print-call-stack cep))
254 (display "Warn: " cep)
255 (for-each (lambda (x) (display x cep)) args))))
257 ;;; define an error procedure for the library
258 (define (slib:error . args)
259 (if (provided? 'trace) (print-call-stack (current-error-port)))
262 ;;; define these as appropriate for your system.
263 (define slib:tab #\tab)
264 (define slib:form-feed #\form)
266 ;;; Define these if your implementation's syntax can support it and if
267 ;;; they are not already defined.
269 ;(define (1+ n) (+ n 1))
270 (define (1- n) (+ n -1))
271 ;(define (-1+ n) (+ n -1))
273 (define program-vicinity
274 (make-simple-switch 'program-vicinity
275 (lambda (x) (or (string? x) (false? x)))
278 (define in-vicinity string-append)
280 ;;; Define SLIB:EXIT to be the implementation procedure to exit or
281 ;;; return if exitting not supported.
282 (define slib:exit (lambda args (exit))
284 (define (string . args) (apply string-append (map char->string args)))
287 (let ((t:make-string (*value standard-env 'make-string)))
289 (let ((str (t:make-string a)))
290 (if b (map-string! (lambda (x) (ignore x) (car b)) str) str)))))
292 (define (string>? a b)
295 ;;start off with n<=(string-length b) and n<=(string-length a)
296 ;;a,b coincide for chars <n
297 (cond ((= (string-length a) n) (< n (string-length b)))
298 ;;now (< n (string-length a))
299 ((= (string-length b) n) '#f)
300 ;;now (< n (string-length a))
301 ((char=? (nthchar a n) (nthchar b n) ) (aux (+ 1 n) a b))
302 ('#t (char<? (nthchar b n) (nthchar a n)))))))
305 (define (string<? a b) (string>? b a))
306 (define (string<=? a b) (not (string>? a b)))
307 (define (string>=? a b) (not (string<? a b)))
309 (define (string-ci<? a b)
310 (string<? (string-upcase a) (string-upcase b)))
312 (define (string-ci>? a b)
313 (string>? (string-upcase a) (string-upcase b)))
315 (define (string-ci<=? a b)
316 (string<=? (string-upcase a) (string-upcase b)))
318 (define (string-ci>=? a b)
319 (string>=? (string-upcase a) (string-upcase b)))
321 ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
322 ;;; use this definition if your system doesn't have such a procedure.
323 ;;; T already has it, but requires 1 argument.
326 (let ((t:force-output (*value standard-env 'force-output)))
329 (t:force-output (car x))
330 (t:force-output (current-output-port))))))
332 ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
333 ;;; port versions of CALL-WITH-*PUT-FILE.
334 (define (call-with-output-string proc)
335 (with-output-to-string var (proc var)))
337 (define (call-with-input-string string proc)
338 (with-input-from-string (variable string) (proc variable)))
340 (define (string->number s . x)
341 (let ((base (if x (car x) 10))
342 (s (string-upcase s)))
343 (or (mem? = base '(8 10 16))
344 (error (format (current-error-port) "Bad radix ~A" base)))
345 (if (= (string-length s) 0) '()
350 (#\1 . 1) (#\2 . 2) (#\3 . 3) (#\4 . 4)
351 (#\5 . 5) (#\6 . 6) (#\7 . 7) (#\8 . 8)
352 (#\9 . 9) (#\A . 10) (#\B . 11) (#\C . 12)
353 (#\D . 13) (#\E . 14) (#\F . 15)))))))
355 (iterate loop ((pos (- (string-length s) 1))
358 (let ((num (char->number (string-ref s pos))))
359 (or num (not-num '()))
360 (or (< num base) (not-num '()))
363 (+ accum (* num power)))))))))))
365 (define (number->string n . x)
366 (let ((rad (if (car x) (car x) 10)))
372 (else (error (format (current-error-port)
373 "Bad radix ~A" (car x)))))
382 (define exact->inexact ->float)
385 (let ((t:peek-char (*value standard-env 'peek-char)))
387 (let ((port (if p (car p) (current-input-port))))
388 (t:peek-char port)))))
390 ;;;(set ((*value scheme-env 'standard-early-binding-env) 'load) '#f)
391 ;;;(set ((*value scheme-env 'standard-early-binding-env) 'substring) '#f)
392 (set ((*value scheme-env 'standard-early-binding-env) 'less?) '#f)
393 (set ((*value scheme-env 'standard-early-binding-env) 'greater?) '#f)
394 (set ((*value scheme-env 'standard-early-binding-env) 'not-less?) '#f)
395 (set ((*value scheme-env 'standard-early-binding-env) 'not-greater?) '#f)
396 (set ((*value scheme-env 'standard-early-binding-env) 'number-equal?) '#f)
397 (set ((*value scheme-internal-env 'standard-early-binding-env) 'list?) '#f)
399 (set ((*value t-implementation-env 'SOURCE-FILE-EXTENSION)) 'scm)
401 ;;; Here for backward compatability
402 (define (scheme-file-suffix) "")
405 (let ((t:load (*value standard-env 'load)))
406 (lambda (filespec . x)
407 (apply t:load (->filename filespec) x))))
409 ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
410 ;;; suffix all the module files in SLIB have. See feature 'SOURCE.
412 (define slib:load-source load)
414 ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
415 ;;; by compiling "foo.scm" if this implementation can compile files.
416 ;;; See feature 'COMPILED.
418 (define slib:load-compiled load)
420 ;;; At this point SLIB:LOAD must be able to load SLIB files.
422 (define slib:load slib:load-source)
424 (slib:load (in-vicinity (library-vicinity) "require") scheme-env)
426 ;;;(define scheme-read-table
427 ;;; (make-read-table standard-read-table 'modified-read-table))
429 ;;;(set (read-table-entry scheme-read-table '#\#)
430 ;;; (lambda (p ch rtable)
431 ;;; (ignore ch) (ignore rtable)
432 ;;; ((*value scheme-env 'string->number)
433 ;;; (symbol->string (read-refusing-eof p)) 16)))
435 ;;;(set (port-read-table (standard-input)) scheme-read-table)