Insert Files

Home, Up: Insert Files and User Defined Elements

 

On this page:

Insert Files, Inserting an Insert File, Other Uses.

 

Insert Files

The content of a file can be inserted in an input line. This has several uses, the most important one being that this way Hypatia can read data from files.

An insert file can contain anything that might be a part of an input line. In most cases, though not necessarily, this will be numbers.

Like all of Hypatia's files insert files are plain text files, and located in Hypatia's program folder.

While the length of an input line is limited by the width of the console window, no such limit exists for inserted files.

Because an insert file gets inserted into an input line, it is considered to be a single line -- if it contains line breaks, they are converted to spaces.

Numbers in an insert file can be written in any format that Hypatia understands -- see chapter "Numbers", page Writing Numbers.

An insert file can contain comment lines, that is, lines that begin with the hash sign # -- Hypatia will ignore these lines.

 

Inserting an Insert File

A file gets inserted into an input line by writing its name in parentheses.

Unlike other files the names of insert files can contain spaces, though this is not recommended -- for instance, you would not be able to open that file with the EDIT filename command.

Spaces before and after the parentheses are recommended, but could be omitted.

 

For example, let's have an insert file named mydata.txt that looks like this:

# This is an example

27 3

5 7 8

10

(All these numbers could as well form a single line, or they could all stand in separate lines -- in an insert file this makes no difference.)

 

To calculate the sum of the numbers in this file, you simply insert the file into the input line:

? (mydata.txt) SUM

= 60

There is no hard limit to the size of an insert file, there could be tens of thousands of numbers in it, though for working with such amount of data you will probably use different tools.

 

Other Uses

As anything that can be entered as part of an input line can be read from an insert file, this mechanism can be used for a variety of purposes. For instance:

You can use an insert file when you need an input line that exceeds the length permitted by the width of the console window.

You can use an insert file if you need a user defined constant that is protected against accidental overwriting -- this has already been shown in chapter "Variables and User-Defined Constants", page "User-Defined Constants".

Insert files could be used for mathematical expressions (see the next page but one, "User Defined Operators"), though this is usually better done with user defined elements (see next page).

You can treat the recent result file hy as an insert file by writing (hy) -- this not only allows you to use the last result when you next start Hypatia after you have closed the program, it also has purposes that will be discussed in chapter "Results" and later chapters.

(hyin) ? repeats the previous calculation in debugging mode, the same as scrolling up and appending a space and a question mark.

 

Home, Up: Insert Files and User Defined Elements, Next: User-Defined Elements