1 ;;;; slib.scm --- definitions needed to get SLIB to work with Guile
3 ;;;; Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
5 ;;;; This file is part of GUILE.
7 ;;;; GUILE is free software; you can redistribute it and/or modify
8 ;;;; it under the terms of the GNU General Public License as
9 ;;;; published by the Free Software Foundation; either version 2, or
10 ;;;; (at your option) any later version.
12 ;;;; GUILE is distributed in the hope that it will be useful, but
13 ;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;;; GNU General Public License for more details.
17 ;;;; You should have received a copy of the GNU General Public
18 ;;;; License along with GUILE; see the file COPYING. If not, write
19 ;;;; to the Free Software Foundation, Inc., 59 Temple Place, Suite
20 ;;;; 330, Boston, MA 02111-1307 USA
22 (define-module (ice-9 slib)
27 (define (eval-load <filename> evl)
28 (if (not (file-exists? <filename>))
29 (set! <filename> (string-append <filename> (scheme-file-suffix))))
30 (call-with-input-file <filename>
32 (let ((old-load-pathname *load-pathname*))
33 (set! *load-pathname* <filename>)
34 (do ((o (read port) (read port)))
37 (set! *load-pathname* old-load-pathname)))))
41 (define slib:exit quit)
42 (define slib:error error)
43 (define slib:warn warn)
44 (define slib:eval (lambda (x) (eval x slib-module)))
45 (define defmacro:eval (lambda (x) (eval x (interaction-environment))))
46 (define logical:logand logand)
47 (define logical:logior logior)
48 (define logical:logxor logxor)
49 (define logical:lognot lognot)
50 (define logical:ash ash)
51 (define logical:logcount logcount)
52 (define logical:integer-length integer-length)
53 (define logical:bit-extract bit-extract)
54 (define logical:integer-expt integer-expt)
55 (define logical:ipow-by-squaring ipow-by-squaring)
56 (define slib:eval-load eval-load)
57 (define slib:tab #\tab)
58 (define slib:form-feed #\page)
60 (define slib-module (current-module))
62 (define (defined? symbol)
63 (module-defined? slib-module symbol))
82 rev4-optional-procedures
86 (if (defined? 'getenv)
90 (if (defined? 'current-time)
94 (if (defined? 'system)
98 (if (defined? 'array?)
102 (if (defined? 'char-ready?)
106 (if (defined? 'array-for-each)
110 (if (and (string->number "0.0") (inexact? (string->number "0.0")))
114 (if (rational? (string->number "1/19"))
118 (if (real? (string->number "0.0"))
122 (if (complex? (string->number "1+i"))
126 (let ((n (string->number "9999999999999999999999999999999")))
127 (if (and n (exact? n))
132 ;;; FIXME: Because uers want require to search the path, this uses
133 ;;; load-from-path, which probably isn't a hot idea. slib
134 ;;; doesn't expect this function to search a path, so I expect to get
135 ;;; bug reports at some point complaining that the wrong file gets
136 ;;; loaded when something accidentally appears in the path before
137 ;;; slib, etc. ad nauseum. However, the right fix seems to involve
138 ;;; changing catalog:get in slib/require.scm, and I don't expect
139 ;;; Aubrey will integrate such a change. So I'm just going to punt
140 ;;; for the time being.
141 (define-public (slib:load name)
142 (save-module-excursion
144 (set-current-module slib-module)
145 (let ((errinfo (catch 'system-error
147 (load-from-path name)
149 (lambda args args))))
154 (string-append name ".scm"))
157 (apply throw errinfo))))))
159 (define slib:load-source slib:load)
160 (define defmacro:load slib:load)
162 (define slib-parent-dir
163 (let* ((path (%search-load-path "slib/require.scm")))
165 (substring path 0 (- (string-length path) 17))
166 (error "Could not find slib/require.scm in " %load-path))))
168 (define-public (implementation-vicinity)
169 (string-append slib-parent-dir "/"))
170 (define-public (library-vicinity)
171 (string-append (implementation-vicinity) "slib/"))
172 (define-public home-vicinity
173 (let ((home-path (getenv "HOME")))
174 (lambda () home-path)))
175 (define-public (scheme-implementation-type) 'guile)
176 (define-public (scheme-implementation-version) "")
178 (define (output-port-width . arg) 80)
179 (define (output-port-height . arg) 24)
180 (define (identity x) x)
184 (define-public (make-random-state . args)
185 (let ((seed (if (null? args) *random-state* (car args))))
186 (cond ((string? seed))
187 ((number? seed) (set! seed (number->string seed)))
189 (require 'object->string)
190 (set! seed (object->limited-string seed 50)))))
191 (seed->random-state seed)))
197 (define offset-time +)
200 (define %system-define define)
203 (procedure->memoizing-macro
205 (if (= (length env) 1)
206 `(define-public ,@(cdr exp))
207 `(%system-define ,@(cdr exp))))))
209 ;;; Hack to make syncase macros work in the slib module
210 (if (nested-ref the-root-module '(app modules ice-9 syncase))
211 (set-object-property! (module-local-variable (current-module) 'define)
215 (define (software-type)
216 "Return a symbol describing the current platform's operating system.
217 This may be one of AIX, VMS, UNIX, COHERENT, WINDOWS, MS-DOS, OS/2,
218 THINKC, AMIGA, ATARIST, MACH, or ACORN.
220 Note that most varieties of Unix are considered to be simply \"UNIX\".
221 That is because when a program depends on features that are not present
222 on every operating system, it is usually better to test for the presence
223 or absence of that specific feature. The return value of
224 @code{software-type} should only be used for this purpose when there is
225 no other easy or unambiguous way of detecting such features."
228 (slib:load (in-vicinity (library-vicinity) "require.scm"))
230 (define-public require require:require)
232 ;; {Extensions to the require system so that the user can add new
233 ;; require modules easily.}
235 (define *vicinity-table*
237 (cons 'implementation (implementation-vicinity))
238 (cons 'library (library-vicinity))))
240 (define (install-require-vicinity name vicinity)
241 (let ((entry (assq name *vicinity-table*)))
243 (set-cdr! entry vicinity)
244 (set! *vicinity-table*
245 (acons name vicinity *vicinity-table*)))))
247 (define (install-require-module name vicinity-name file-name)
248 (if (not *catalog*) ;Fix which loads catalog in slib
249 (catalog:get 'random)) ;(doesn't load the feature 'random)
250 (let ((entry (assq name *catalog*))
251 (vicinity (cdr (assq vicinity-name *vicinity-table*))))
252 (let ((path-name (in-vicinity vicinity file-name)))
254 (set-cdr! entry path-name)
256 (acons name path-name *catalog*))))))