Previous Up Next

4.1.1  Writing variable values to a file

The write command saves variable values to a file, to be read later.

Example

a:=3.14 b:=7 write("foo",a,b)

creates a file named “foo” containing:

a:=(3.14); b:=7;

If you wanted to store the first million digits of π to a file, you could set it equal to a variable and store it in a file:

pidec:=evalf(pi,10^6):; write("pi1million",pidec)

The file is written so that it can be loaded with the read command (Section 4.1.3), which simply takes a file name as a string. This allows you to restore the values of variables saved this way, for example in a different session or if you have purged the variables.

Example

If, in a different session, you want to use the values of a and b above, enter:

read("foo")

This will reassign the values 3.14 and 7 to a and b. Be careful, this will silently overwrite any values that a and b might have had.


Previous Up Next