You are looking at historical revision 19148 of this page. It may differ significantly from its current revision.
Fast I/O procedures specialized for different types. Instead of using the Scheme procedure read, specialized procedures can be used, so:
- I/O is faster, particularly if you have loaded the numbers egg
- There is no need to check the result of read
(use specialized-io) (let ((v (read-flonum (current-input-port)))) (write-flonum (fp* 2.5 v) (current-output-port)))
Note that you can use fp* with a value returned from read-flonum (it's guaranteed to be a flonum).
Documentation[procedure] (read-fixnum PORT)
[procedure] (read-flonum PORT)
[procedure] (read-complex PORT)
[procedure] (read-one-char PORT)
These procedures read one object of a specific type from an input-port. There are no runtime checks in the Scheme way; the procedures will just call error if anything goes wront (EOF, lexical error etc).[procedure] (write-fixnum VALUE PORT)
[procedure] (write-flonum VALUE PORT)
[procedure] (write-complex VALUE PORT)
[procedure] (write-one-char VALUE PORT)
These procedures write one object of a specific type to an output-port. There are no runtime checks in the Scheme way; the procedures will just call error if anything goes wront (EOF, lexical error etc).[procedure] (write-one-string STRING PORT)
This procedure writes a string to the output port.[procedure] (read-string-until CHAR PORT)
[procedure] (read-string-between LEFTCHAR RIGHTCHAR PORT)
These procedures read a string from the input port. read-string-until will read from the current position of the stream until CHAR is found (and CHAR will be included in the resulting string). read-string-between will first search for LEFTCHAR then read until RIGHTCHAR is found.[parameter] specialized-io-error
This variable should be bound to a procedure that will be called when parsing fails. By default it's bound to error.[parameter] +specialized-io-string-buffer-size+
This is the size of the buffer in which strings are read. When the buffer becomes full, its size is doubled. This default value is 500.
(use specialized-io) (let ((n (read-fixnum port))) (do ((i 0 (fx+ 1 i))) ((fx= i n)) (f64vector-set! vec i (read-flonum port))))
- 1.1 String reading and writing added
- 1.0 Initial Release
Copyright (c) 2010, Jeronimo C. Pellegrini All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.