[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[S8] Chunk readers and fileIn

S8 use fileIn framework (browse here) to produce system changes.

The fileIn is a procedure designed to communicate changes (contents & behavior) between Smalltalk systems.
A smalltalk systems connected through a channel can listen and change according to the data flowing from the channel stream.

The format of the shared data is known as "chunk format"; it can contain source code or any resource.

In case of two systems talking, one system (acting as source or information) can send classes/methods and/or code to evaluate, that produce changes in the listener system. This changes can be used to teach the listener to do more and also instruct on how to read more data from source (reader classes can flow through the communication stream, just before data is transferred).

In case of files, communication is unidirectional and the default S8 image contain readers capable to read code (s8 code and javascript); and evaluate any expression while reading.

The power of FileIn framework is reflected by the fact that the source system can teach and transfer any domain model through the channel to the listener and objects in the listener system can act on the incoming data.
While reading, the FileInReader can change to read chunks in the stream in any format.

U8 tools use chunk format to present behavior and structure of the system in text panes.
The contents of text panes (and selections) can be "accepted" to activate a fileIn process with default FileInReader.
This make easy to edit and manage multiple elements in one pane (e.g. multiple methods of different classes in the system can be edited and accepted in one pane).

FileIn process

The #fileIn message is understood by String and Stream instances (Strings will send #fileIn to the result of sending #stream message to the receiver).
Stream implement #fileIn reading in a loop until stream is atEnd.
For each read operation it will send #scanFrom: (the stream) to an internal (fileIn)"reader".
The (fileIn)reader is nil at startup.
Any object responds to #scanFrom:.
At Object level, #scanFrom: will read the next chunk of data and evaluate the text in the chunk; returning the result of evaluation as result of the scan.
So, any object implement a simple fileIn procedure and continue the scanning... but if it is returned an object that implement #scanFrom: in another way, it can process the stream in other format.

The default input format is text (to be evaluated) in chunks; but at each step, the format can change if another reader is returned as result of evaluating a chunk.
This technique is used to teach the reader system to fileIn new data while reading.

The chunk format

The default implementation for reading a "chunk" of data from a stream is returning the contents in the stream up to the next ! (admiration character). If another ! is found at end of the chunk, it is appended to the read contents with the result of reading the next chunk.

NoteThe ! is the escape character if you need a chunk containind $! in the text.

Examples of use