Clarify description of --enable-threads.
[bpt/guile.git] / ice-9 / r4rs.scm
CommitLineData
98c27b65
JB
1;;;; r4rs.scm --- definitions needed for libguile to be R4RS compliant
2;;;; Jim Blandy <jimb@cyclic.com> --- October 1996
3
75a97b92 4;;;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
98c27b65
JB
5;;;;
6;;;; This program is free software; you can redistribute it and/or modify
7;;;; it under the terms of the GNU General Public License as published by
8;;;; the Free Software Foundation; either version 2, or (at your option)
9;;;; any later version.
10;;;;
11;;;; This program is distributed in the hope that it will be useful,
12;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;;; GNU General Public License for more details.
15;;;;
16;;;; You should have received a copy of the GNU General Public License
17;;;; along with this software; see the file COPYING. If not, write to
18;;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20\f
21;;;; apply and call-with-current-continuation
22
06a02069
MD
23;;; We want these to be tail-recursive, so instead of using primitive
24;;; procedures, we define them as closures in terms of the primitive
25;;; macros @apply and @call-with-current-continuation.
98c27b65
JB
26(set! apply (lambda (fun . args) (@apply fun (apply:nconc2last args))))
27(define (call-with-current-continuation proc)
28 (@call-with-current-continuation proc))
29
30\f
31;;;; Basic Port Code
32
33;;; Specifically, the parts of the low-level port code that are written in
34;;; Scheme rather than C.
35;;;
36;;; WARNING: the parts of this interface that refer to file ports
37;;; are going away. It would be gone already except that it is used
38;;; "internally" in a few places.
39
40
41;; OPEN_READ, OPEN_WRITE, and OPEN_BOTH are used to request the proper
42;; mode to open files in. MSDOS does carraige return - newline
43;; translation if not opened in `b' mode.
44;;
45(define OPEN_READ (case (software-type)
46 ((MS-DOS WINDOWS ATARIST) "rb")
47 (else "r")))
48(define OPEN_WRITE (case (software-type)
49 ((MS-DOS WINDOWS ATARIST) "wb")
50 (else "w")))
51(define OPEN_BOTH (case (software-type)
52 ((MS-DOS WINDOWS ATARIST) "r+b")
53 (else "r+")))
54
55(define *null-device* "/dev/null")
56
57(define (open-input-file str)
58 (open-file str OPEN_READ))
59
60(define (open-output-file str)
61 (open-file str OPEN_WRITE))
62
63(define (open-io-file str) (open-file str OPEN_BOTH))
64(define close-input-port close-port)
65(define close-output-port close-port)
66(define close-io-port close-port)
67
68(define (call-with-input-file str proc)
69 (let* ((file (open-input-file str))
70 (ans (proc file)))
71 (close-input-port file)
72 ans))
73
74(define (call-with-output-file str proc)
75 (let* ((file (open-output-file str))
76 (ans (proc file)))
77 (close-output-port file)
78 ans))
79
80(define (with-input-from-port port thunk)
81 (let* ((swaports (lambda () (set! port (set-current-input-port port)))))
82 (dynamic-wind swaports thunk swaports)))
83
84(define (with-output-to-port port thunk)
85 (let* ((swaports (lambda () (set! port (set-current-output-port port)))))
86 (dynamic-wind swaports thunk swaports)))
87
88(define (with-error-to-port port thunk)
89 (let* ((swaports (lambda () (set! port (set-current-error-port port)))))
90 (dynamic-wind swaports thunk swaports)))
91
92(define (with-input-from-file file thunk)
93 (let* ((nport (open-input-file file))
94 (ans (with-input-from-port nport thunk)))
95 (close-port nport)
96 ans))
97
98(define (with-output-to-file file thunk)
99 (let* ((nport (open-output-file file))
100 (ans (with-output-to-port nport thunk)))
101 (close-port nport)
102 ans))
103
104(define (with-error-to-file file thunk)
105 (let* ((nport (open-output-file file))
106 (ans (with-error-to-port nport thunk)))
107 (close-port nport)
108 ans))
109
110(define (with-input-from-string string thunk)
111 (call-with-input-string string
112 (lambda (p) (with-input-from-port p thunk))))
113
114(define (with-output-to-string thunk)
115 (call-with-output-string
116 (lambda (p) (with-output-to-port p thunk))))
117
118(define (with-error-to-string thunk)
119 (call-with-output-string
120 (lambda (p) (with-error-to-port p thunk))))
121
122(define the-eof-object (call-with-input-string "" (lambda (p) (read-char p))))
123
124\f
125;;;; Loading
126
0065d90e 127(if (not (defined? '%load-verbosely))
98c27b65
JB
128 (define %load-verbosely #f))
129(define (assert-load-verbosity v) (set! %load-verbosely v))
130
131(define (%load-announce file)
132 (if %load-verbosely
133 (with-output-to-port (current-error-port)
134 (lambda ()
135 (display ";;; ")
136 (display "loading ")
137 (display file)
138 (newline)
139 (force-output)))))
140
141(set! %load-hook %load-announce)
142
98c27b65
JB
143(define (load name)
144 (start-stack 'load-stack
75a97b92 145 (primitive-load name)))