Chapter 12. Input and Output

Table of Contents

12.1. Referencing Files
12.2. Lisp and Gamma I/O mechanisms
12.3. Writing
12.3.1. Print vs. Princ
12.3.2. Write vs. Writec
12.3.3. Terpri
12.3.4. Pretty Printing
12.3.5. Printing Circular References
12.4. Reading
12.4.1. Reading Gamma Expressions
12.4.2. Reading Arbitrary ASCII Data
12.4.3. Reading Binary Data

12.1. Referencing Files

As in C, there are two ways to reference a file in Gamma, using a descriptor or a pointer.

A file descriptor is an integer that identifies an open file within a process. This is the lowest-level handle available for interacting with the open file. Disk files, pseudo-ttys, IP sockets, UNIX-domain sockets, pipes and other facilities all offer interaction through file descriptors.

A file pointer is an abstraction of the file that adds buffering on input and output. This would be of type FILE* in C. The reason this exists is that it is very inefficient to use a file descriptor, which does not perform any in-process buffering where many reads and writes are being performed. The file pointer stores many write requests until it has enough data to perform a more efficient write to disk, hopefully in multiples of the disk block size.

In Gamma, a file pointer is an opaque structure (the internals are not visible to the programmer) that is effectively a buffered file. (See the note in open.) It's abstracted a little further to also include strings as file pointers, when they are opened using open_string.

Some Gamma I/O functions work with file descriptors (generally those that start with fd_), others work with file pointers, and a few work with both.