summaryrefslogtreecommitdiffstats
path: root/gambit.init
diff options
context:
space:
mode:
Diffstat (limited to 'gambit.init')
-rw-r--r--gambit.init300
1 files changed, 192 insertions, 108 deletions
diff --git a/gambit.init b/gambit.init
index 2e8a10d..d50edae 100644
--- a/gambit.init
+++ b/gambit.init
@@ -3,14 +3,16 @@
;;;
;;; This code is in the public domain.
-;;; Ignore case when reading symbols (per R5RS).
-(set-case-conversion! #t)
-
;;; Updated 1992 February 1 for Gambit v1.71 -- by Ken Dickey
;;; Date: Wed, 12 Jan 1994 15:03:12 -0500
;;; From: barnett@armadillo.urich.edu (Lewis Barnett)
;;; Relative pathnames for Slib in MacGambit
;;; Hacked yet again for Gambit v2.4, Jan 1997, by Mike Pope
+;;; Updated for Gambit v3.0, 2001-01 AGJ.
+
+;;; gsi should be invoked with -:s option to Ignore case when reading
+;;; symbols (per R5RS).
+
(define (software-type) 'MACOS) ; for MacGambit.
(define (software-type) 'UNIX) ; for Unix platforms.
@@ -22,13 +24,11 @@
(define (scheme-implementation-home-page)
"http://www.iro.umontreal.ca/~gambit/index.html")
-(define (scheme-implementation-version) "3.0")
-;;; Jefferson R. Lowrey reports that in Gambit Version 3.0
-;;; (argv) returns '("").
-(define argv
- (if (equal? '("") (argv)) ;Fix only if it is broken.
- (lambda () '("Lowrey HD:Development:MacGambit 3.0:Interpreter"))
- argv))
+(define (scheme-implementation-version) (system-version-string))
+
+(define getenv
+ (let ((ge getenv))
+ (lambda (str) (ge str #f))))
;;; (implementation-vicinity) should be defined to be the pathname of
;;; the directory where any auxillary files to your Scheme
@@ -55,85 +55,196 @@
;;; called slib in the same directory as the MacGambit Interpreter.
(define library-vicinity
(let ((library-path
- (case (software-type)
- ((UNIX) "/usr/local/lib/slib/")
- ((MACOS) (string-append (implementation-vicinity) "slib:"))
- ((AMIGA) "dh0:scm/Library/")
- ((VMS) "lib$scheme:")
- ((WINDOWS MS-DOS) "C:\\SLIB\\")
- (else ""))))
+ (or
+ ;; Use this getenv if your implementation supports it.
+ (getenv "SCHEME_LIBRARY_PATH")
+ ;; Use this path if your scheme does not support GETENV
+ ;; or if SCHEME_LIBRARY_PATH is not set.
+ (case (software-type)
+ ((UNIX) "/usr/local/lib/slib/")
+ ((MACOS) (string-append (implementation-vicinity) "slib:"))
+ ((AMIGA) "dh0:scm/Library/")
+ ((VMS) "lib$scheme:")
+ ((WINDOWS MS-DOS) "C:\\SLIB\\")
+ (else "")))))
(lambda () library-path)))
;;; (home-vicinity) should return the vicinity of the user's HOME
;;; directory, the directory which typically contains files which
;;; customize a computer environment for a user.
-(define home-vicinity
+(define (home-vicinity)
+ (let ((home (getenv "HOME")))
+ (if home
+ (case (software-type)
+ ((UNIX COHERENT MS-DOS) ;V7 unix has a / on HOME
+ (if (eqv? #\/ (string-ref home (+ -1 (string-length home))))
+ home
+ (string-append home "/")))
+ (else home))
+ (case (software-type)
+ ((VMS) "~:")
+ ((WINDOWS) "~/")
+ ((MACOS) "~:")
+ (else #f)))))
+;@
+(define in-vicinity string-append)
+;@
+(define (user-vicinity)
(case (software-type)
- ((UNIX) (lambda () "~/"))
- ((VMS) (lambda () "~:"))
- ((MS-DOS) (lambda () "~\\"))
- ((WINDOWS) (lambda () "~/"))
- ((MACOS) (lambda () "~:"))))
-
-;;; *FEATURES* should be set to a list of symbols describing features
-;;; of this implementation. Suggestions for features are:
+ ((VMS) "[.]")
+ (else "")))
+
+(define *load-pathname* #f)
+;@
+(define vicinity:suffix?
+ (let ((suffi
+ (case (software-type)
+ ((AMIGA) '(#\: #\/))
+ ((MACOS THINKC) '(#\:))
+ ((MS-DOS WINDOWS ATARIST OS/2) '(#\\ #\/))
+ ((NOSVE) '(#\: #\.))
+ ((UNIX COHERENT PLAN9) '(#\/))
+ ((VMS) '(#\: #\]))
+ (else
+ (slib:warn "require.scm" 'unknown 'software-type (software-type))
+ "/"))))
+ (lambda (chr) (and (memv chr suffi) #t))))
+;@
+(define (pathname->vicinity pathname)
+ (let loop ((i (- (string-length pathname) 1)))
+ (cond ((negative? i) "")
+ ((vicinity:suffix? (string-ref pathname i))
+ (substring pathname 0 (+ i 1)))
+ (else (loop (- i 1))))))
+(define (program-vicinity)
+ (if *load-pathname*
+ (pathname->vicinity *load-pathname*)
+ (slib:error 'program-vicinity " called; use slib:load to load")))
+;@
+(define sub-vicinity
+ (case (software-type)
+ ((VMS) (lambda
+ (vic name)
+ (let ((l (string-length vic)))
+ (if (or (zero? (string-length vic))
+ (not (char=? #\] (string-ref vic (- l 1)))))
+ (string-append vic "[" name "]")
+ (string-append (substring vic 0 (- l 1))
+ "." name "]")))))
+ (else (let ((*vicinity-suffix*
+ (case (software-type)
+ ((NOSVE) ".")
+ ((MACOS THINKC) ":")
+ ((MS-DOS WINDOWS ATARIST OS/2) "\\")
+ ((UNIX COHERENT PLAN9 AMIGA) "/"))))
+ (lambda (vic name)
+ (string-append vic name *vicinity-suffix*))))))
+;@
+(define (make-vicinity <pathname>) <pathname>)
+;@
+(define with-load-pathname
+ (let ((exchange
+ (lambda (new)
+ (let ((old *load-pathname*))
+ (set! *load-pathname* new)
+ old))))
+ (lambda (path thunk)
+ (let ((old #f))
+ (dynamic-wind
+ (lambda () (set! old (exchange path)))
+ thunk
+ (lambda () (exchange old)))))))
+
+;;@ *FEATURES* is a list of symbols naming the (SLIB) features
+;;; initially supported by this implementation.
(define *features*
'(
source ;can load scheme source files
- ;(slib:load-source "filename")
+ ;(SLIB:LOAD-SOURCE "filename")
compiled ;can load compiled files
- ;(slib:load-compiled "filename")
+ ;(SLIB:LOAD-COMPILED "filename")
+ vicinity
+ srfi-59
+
+ ;; Scheme report features
+ ;; R5RS-compliant implementations should provide all 9 features.
+
+;;; r5rs ;conforms to
+;;; eval ;R5RS two-argument eval
+ values ;R5RS multiple values
+ dynamic-wind ;R5RS dynamic-wind
+;;; macro ;R5RS high level macros
+ delay ;has DELAY and FORCE
+ multiarg-apply ;APPLY can take more than 2 args.
+ char-ready?
+ rev4-optional-procedures ;LIST-TAIL, STRING-COPY,
+ ;STRING-FILL!, and VECTOR-FILL!
+
+ ;; These four features are optional in both R4RS and R5RS
+
+ multiarg/and- ;/ and - can take more than 2 args.
+ rationalize
+ transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF
+ with-file ;has WITH-INPUT-FROM-FILE and
+ ;WITH-OUTPUT-TO-FILE
+
r4rs ;conforms to
-; r3rs ;conforms to
+
ieee-p1178 ;conforms to
-; srfi ;srfi-0, COND-EXPAND finds all srfi-*
- sicp ;runs code from Structure and
- ;Interpretation of Computer
- ;Programs by Abelson and Sussman.
- rev4-optional-procedures ;LIST-TAIL, STRING->LIST,
- ;LIST->STRING, STRING-COPY,
- ;STRING-FILL!, LIST->VECTOR,
- ;VECTOR->LIST, and VECTOR-FILL!
-; rev2-procedures ;SUBSTRING-MOVE-LEFT!,
+
+;;; r3rs ;conforms to
+
+;;; rev2-procedures ;SUBSTRING-MOVE-LEFT!,
;SUBSTRING-MOVE-RIGHT!,
;SUBSTRING-FILL!,
;STRING-NULL?, APPEND!, 1+,
;-1+, <?, <=?, =?, >?, >=?
- multiarg/and- ;/ and - can take more than 2 args.
- multiarg-apply ;APPLY can take more than 2 args.
- rationalize
- delay ;has DELAY and FORCE
- with-file ;has WITH-INPUT-FROM-FILE and
- ;WITH-OUTPUT-TO-FILE
- string-port ;has CALL-WITH-INPUT-STRING and
- ;CALL-WITH-OUTPUT-STRING
- transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF
- char-ready?
-; macro ;has R4RS high level macros
- defmacro ;has Common Lisp DEFMACRO
-; record ;has user defined data structures
-; values ;proposed multiple values
-; dynamic-wind ;proposed dynamic-wind
- ieee-floating-point ;conforms to
+;;; object-hash ;has OBJECT-HASH
+
full-continuation ;can return multiple times
-; object-hash ;has OBJECT-HASH
+ ieee-floating-point ;conforms to IEEE Standard 754-1985
+ ;IEEE Standard for Binary
+ ;Floating-Point Arithmetic.
-; sort
+ ;; Other common features
+
+ srfi ;srfi-0, COND-EXPAND finds all srfi-*
+ sicp ;runs code from Structure and
+ ;Interpretation of Computer
+ ;Programs by Abelson and Sussman.
+ defmacro ;has Common Lisp DEFMACRO
+;;; record ;has user defined data structures
+ structure ;DEFINE-STRUCTURE macro
+ string-port ;has CALL-WITH-INPUT-STRING and
+ ;CALL-WITH-OUTPUT-STRING
+;;; sort
pretty-print
-; object->string
-; format
+ object->string
+;;; format
trace ;has macros: TRACE and UNTRACE
- break
-; compiler ;has (COMPILER)
-; ed ;(ED) is editor
+;;; compiler ;has (COMPILER)
+;;; ed ;(ED) is editor
system ;posix (system <string>)
-; getenv ;posix (getenv <string>)
- program-arguments ;returns list of strings (argv)
-; current-time ;returns time in seconds since 1/1/1970
- ))
+ getenv ;posix (getenv <string>)
+;;; program-arguments ;returns list of strings (argv)
+ current-time ;returns time in seconds since 1/1/1970
+
+ ;; Implementation Specific features
+
+ break
+
+ ))
+
+(define object->limited-string object->string)
+
+(define (difftime caltime1 caltime0)
+ (- (time->seconds caltime1)
+ (if (number? caltime0) caltime0 (time->seconds caltime0))))
+(define (offset-time caltime offset)
+ (seconds->time (+ (time->seconds caltime) offset)))
;;; (OUTPUT-PORT-WIDTH <port>)
-(define (output-port-width . arg) 79)
+;; (define (output-port-width . arg) 79)
;;; (OUTPUT-PORT-HEIGHT <port>)
(define (output-port-height . arg) 24)
@@ -151,27 +262,22 @@
;;; Gambit supports SYSTEM as an "Unstable Addition"; Watch for changes.
(define system ##shell-command)
-;;; (FILE-EXISTS? <string>)
-;(define (file-exists? f) #f)
-
-;;; (DELETE-FILE <string>)
-(define (delete-file f) #f)
-
-;;; FORCE-OUTPUT flushes any pending output on optional arg output port
-;;; use this definition if your system doesn't have such a procedure.
-(define force-output flush-output)
-
-;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
-;;; port versions of CALL-WITH-*PUT-FILE.
+;;; CALL-WITH-INPUT-STRING is good as is. Gambit's
+;;; CALL-WITH-OUTPUT-STRING lengthens the string first argument.
+(define call-with-output-string
+ (let ((cwos call-with-output-string))
+ (lambda (proc) (cwos "" proc))))
(define (make-exchanger obj)
(lambda (rep) (let ((old obj)) (set! obj rep) old)))
-(define (open-file filename modes)
- (case modes
- ((r rb) (open-input-file filename))
- ((w wb) (open-output-file filename))
- (else (slib:error 'open-file 'mode? modes))))
-(define (port? obj) (or (input-port? port) (output-port? port)))
+(define open-file
+ (let ((open-both open-file))
+ (lambda (filename modes)
+ (case modes
+ ((r rb) (open-input-file filename))
+ ((w wb) (open-output-file filename))
+ ((rw rwb) (open-both filename))
+ (else (slib:error 'open-file 'mode? modes))))))
(define (call-with-open-ports . ports)
(define proc (car ports))
(cond ((procedure? proc) (set! ports (cdr ports)))
@@ -181,12 +287,6 @@
(let ((ans (apply proc ports)))
(for-each close-port ports)
ans))
-(define (close-port port)
- (cond ((input-port? port)
- (close-input-port port)
- (if (output-port? port) (close-output-port port)))
- ((output-port? port) (close-output-port port))
- (else (slib:error 'close-port 'port? port))))
(define (browse-url url)
(define (try cmd) (eqv? 0 (system (sprintf #f cmd url))))
@@ -215,9 +315,6 @@
;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
(define slib:eval eval)
-; Define program-arguments as argv
-(define program-arguments argv)
-
;;; If your implementation provides R4RS macros:
;(define macro:eval slib:eval)
;(define macro:load load)
@@ -256,18 +353,7 @@
(define (defmacro:load <pathname>)
(slib:eval-load <pathname> defmacro:eval))
-
-(define (slib:eval-load <pathname> evl)
- (if (not (file-exists? <pathname>))
- (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
- (call-with-input-file <pathname>
- (lambda (port)
- (let ((old-load-pathname *load-pathname*))
- (set! *load-pathname* <pathname>)
- (do ((o (read port) (read port)))
- ((eof-object? o))
- (evl o))
- (set! *load-pathname* old-load-pathname)))))
+;; slib:eval-load definition moved to "require.scm"
(define print-call-stack identity) ;noop
@@ -298,10 +384,8 @@
(define (-1+ n) (- n 1))
(define 1- -1+)
-(define in-vicinity string-append)
-
;;; Define SLIB:EXIT to be the implementation procedure to exit or
-;;; return if exitting not supported.
+;;; return if exiting not supported.
(define slib:exit (lambda args (exit)))
;;; Here for backward compatability