On this page:
The Result File hy, Accumulation Mode, Line Breaks in hy.
There are exceptions which we'll discuss below, but after a calculation the result is assigned to the pseudo variable $ (see page "Chain Calculations" in chapter "First Steps"), and also written to the result file hy, replacing its previous content.
While $ has the exact value of the result, the result gets written to hy according to the specified output format, the way it gets displayed on the screen (see page "Output Format" in chapter "Numbers").
You can use the content of hy in a calculation by treating hy as an insert file, that is, by writing (hy) -- this will become important in the context of accumulation mode.
In two cases a calculation result does not get written to hy:
- within a script (about scripts see the next chapter), unless you force it to be written.
- in "silent mode", when you add a hash sign # at the end of a calculation line. A space before # is needed.
Silent mode, like accumulation mode (see below), applies only to the specific calculation line.
Note that only calculation lines have "results." Variable assignment commands, or (see the next chapter) IF ... THEN conditions neither update $ nor the result file hy.
You can view the content of hy with the command HY unless it has more than 40 lines or 4000 characters.
You can open hy in an external editor (by default notepad.exe) with the command EDIT.
There is a lot more to the result file hy than we have seen so far.
It is a major feature of Hypatia that you can "accumulate" results -- either to perform tasks that return more than one result, or to use the accumulated results for new calculations.
Let us think of a floor plan with four rooms -- in meters, 2 by 1.5, 4 by 3, 5 by 3, and 6 by 4.
The total area is easily calculated:
? 2 1.5 * 4 3 * 5 3 * 6 4 * SUM
But what if you not only want to know the total area, but also the areas of the individual rooms?
Let's start with the first one:
? 2 1.5 *
= 3
Accumulation mode lets us keep this result, while adding the next one -- accumulation mode is enabled by adding an ampersand & after the calculation line. (A space before & is needed.)
Let's do this for the three remaining rooms:
? 4 3 * &
= 12
? 5 3 * &
= 15
? 6 4 * &
= 24
The file hy now has all four results. The command HY shows the content of hy (up to 40 lines or 4000 characters -- there is no limit to the actual number of results that hy can contain).
? HY
3 12 15 24
And to calculate the sum of these four results, we simply insert hy in the calculation line:
? (hy) SUM
= 54
Note that this result overwrites the data in hy. If you want to keep them (maybe for further calculations, like their mean value), you have two options:
Use silent mode:
? (hy) SUM #
Then you can calculate the mean:
? (hy) MEAN
Or you assign the content of hy to a user-defined element:
? @rooms = (hy)
When a file gets read into a user-defined element, then this UDE remains unchanged when the file changes.
Therefore using @rooms instead of (hy) lets you do any number of calculations with the data that got accumulated in hy without risking to delete them by forgetting to use silent mode:
? @rooms SUM
? @rooms MEAN
This has been a very simple example. We will return to it in the chapter "Loop and Script Examples" on page "Loop Example: Rectangles", where we will read the data from a file with no limits to the number of "rooms" or data tuples, but accumulation mode really has a wide range of uses.
Within a script (that is, before the script ends) hy only gets updated in accumulation mode -- more about that in the next chapters.
This will become relevant in the context of scripts and loops, but there are cases where you may not want all results to be written to hy in a single line but may want to have them in separate lines, or insert line breaks at certain points.
When you use hy as an insert file line breaks make no difference, but they can be important in case that you want to use the data with other software, or print it, etc.
To write a result into a new line, you add a double ampersand && at the end of the calculation line. (A space before && is needed.)
Let's repeat the above example, but we want the results of the third and fourth room in a different line from those of the first two rooms:
? 2 1.5 *
= 3
? 4 3 * &
= 12
? 5 3 * &&
= 15
? 6 4 * &
= 24
After the second room we have inserted a line break. Our result file now looks like this:
? HY
3 12
15 24
In the chapter "Loop and Script Examples" we will see an example of line breaks in the result file being useful.