9.24 FileΒΆ

The File(S) domain provides a basic interface to read and write values of type S in files.

Before working with a file, it must be made accessible to FriCAS with the openopenFile operation.

ifile:File List Integer:=open("/tmp/jazz1","output")
\[\]
“/tmp/jazz1”

Type: File List Integer

The openopenFile function arguments are a FileName and a String specifying the mode. If a full pathname is not specified, the current default directory is assumed. The mode must be one of input or output. If it is not specified, input is assumed. Once the file has been opened, you can read or write data.

The operations readreadFile and writewriteFile are provided.

write!(ifile, [-1,2,3])
\[\]
[-1,2,3]

Type: List Integer

write!(ifile, [10,-10,0,111])
\[\]
[10,-10,0,111]

Type: List Integer

write!(ifile, [7])
\[\]
[7]

Type: List Integer

You can change from writing to reading (or vice versa) by reopening a file.

reopen!(ifile, "input")
\[\]
“/tmp/jazz1”

Type: File List Integer

read! ifile
\[\]
[-1,2,3]

Type: List Integer

read! ifile
\[\]
[10,-10,0,111]

Type: List Integer

The readreadFile operation can cause an error if one tries to read more data than is in the file. To guard against this possibility the readIfCanreadIfCanFile operation should be used.

readIfCan! ifile
\[\]
[7]

Type: Union(List Integer,...)

readIfCan! ifile
\[\]
“failed”

Type: Union(“failed”,...)

You can find the current mode of the file, and the file’s name.

iomode ifile
\[\]
“input”

Type: String

name ifile
\[\]
“/tmp/jazz1”

Type: FileName

When you are finished with a file, you should close it.

close! ifile
\[\]
“/tmp/jazz1”

Type: File List Integer

)system rm /tmp/jazz1

A limitation of the underlying LISP system is that not all values can be represented in a file. In particular, delayed values containing compiled functions cannot be saved.

For more information on related topics, see TextFileXmpPage , KeyedAccessFileXmpPage , LibraryXmpPage , and FileNameXmpPage .