| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
String ports are the ports that you can read from or write to memory.
string-ref with incremental index.
(define p (open-input-string "foo x")) (read p) => foo (read-char p) => #\space (read-char p) => #\x (read-char p) => #<eof> (read-char p) => #<eof> |
get-output-string.
This is a far more efficient way to construct a string
sequentially than pre-allocate a string and fill it with
string-set!.
port and returns a string
that has been accumulated to port so far.
If a byte data has been written to the port, this function
re-scans the buffer to see if it can consist a complete string;
if not, an incomplete string is returned.
(define (call-with-output-string proc)
(let ((out (open-output-string)))
(proc out)
(get-output-string out)))
(define (call-with-input-string str proc)
(let ((in (open-input-string str)))
(proc in)))
(define (with-output-to-string thunk)
(let ((out (open-output-string)))
(with-output-to-port out thunk)
(get-output-string out)))
(define (with-input-from-string str thunk)
(with-input-from-port (open-input-string str) thunk))
|
(define (call-with-string-io str proc)
(let ((out (open-output-string))
(in (open-input-string str)))
(proc in out)
(get-output-string out)))
(define (with-string-io str thunk)
(with-output-to-string
(lambda ()
(with-input-from-string str
thunk))))
|
(write-to-string obj writer) == (with-output-to-string (lambda () (writer obj))) (read-from-string string) == (with-input-from-string string read) |
write.
The default values of start and end is 0 and
the length of string.
Portability note: Common Lisp has these functions, with
different optional arguments.
STk has read-from-string without optional argument.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |