next up previous contents index
Next: error Up: String Previous: char   Contents   Index


coerce


Usage

c::%
s::TextReader
s::TextWriter


Signatures

coerce: Character $\to$ %
coerce: % $\to$ TextReader
coerce: % $\to$ TextWriter


Parameter Type Description
c Character a character
s % a string


Description

c::String converts the character c to the string ``c'', while s::T where T is an I/O stream type converts the string s to a text reader or writer, allowing one to read data or write data to it.


Remarks

When writing to a string, you must ensure that the string is large enough for all the data that will be written to it, since the string will not be extended and this function does not protect you against overwriting. When reading from or writing to a string, each coercion to a reader or writer resets the stream to the beginning of the string, and the string is not side-affected by the subsequent read or write operations, while the stream is side-affected. Thus, when reading several values from the same string, you must assign the reader to a variable and read the values from that variable, as in the example below.


Example

import from MachineInteger, String;
s := "  12  56";
a:MachineInteger := << s::TextReader;
b:MachineInteger := << s::TextReader;
assigns the value 12 to both a and b, while
import from MachineInteger, String;
s := "  12  56";
p := s::TextReader;
a:MachineInteger := << p;
b:MachineInteger := << p;
assigns 12 to a and 56 to b.


See Also

PrimitiveMemoryBlock

coerce
next up previous contents index
Next: error Up: String Previous: char   Contents   Index
Manuel Bronstein 2004-06-28