HY, Silent Mode and Accumulation Mode

Home, Up: Results

 

On this page:

The Result $, The Result File hy, Silent Mode, Accumulation Mode, Line Breaks in hy.

 

The Result $

Any calculation in Hypatia has a result which corresponds to the pseudo variable $ (see page Chain Calculations, $ and $$ in chapter "First Steps"). When you start Hypatia its value is 0.

The value of $ remains unchanged until the next calculation.

After each calculation the result (the value of $) is shown in the chosen output format, preceded by an = sign, unless the calculation is done in a script (see chapter Scripts) or in a loop (see chapter Loops).

In a script all results are shown when the script is called with the command RUN filename, but only the last result is shown after the end of the script when the script is called with _filename.

If the script does not include a calculation, no result is shown at the end of the script.

Within a loop, though, results are never shown, but the value of $ is always shown at the end of a loop, even if no calculation was performed.

 

Three things are important to keep in mind:

Assigning a value to a variable does not count as a calculation, even if it involves a calculation. Likewise any calculation performed in an IF ... THEN clause does not count. In both cases $ remains unchanged, and is not shown.

After a loop the value of $ will always be shown, whether the loop (or the script called by the loop) performed any calculation or not. The result shown after a loop may not be what you are looking for -- that could be the value of a variable, or the content of the result file hy -- and may be irrelevant or, if you're not aware of this fact, even misleading.

Within a loop results are not shown, but they are still written to hy, unless the calculation line uses silent mode (see below) -- using silent mode for calculations makes a loop much faster.

 

The Result File hy

There are exceptions which we'll discuss below, but after a calculation the result is not only assigned to the pseudo variable $ but also written to the result file hy, replacing its previous content.

While $ has the exact value of the result, this 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").

The content of hy is always a number or (see "Accumulation Mode" below) a series of numbers.

You can use the content of hy in a calculation by treating hy as an insert file, that is, by writing (hy).

In two cases a calculation result does not get written to hy:

- In a script before the end of the script (about scripts see the next chapter), unless you force it to be written by using accumulation mode (see below). (Note that if the script is called in a loop, the "end of the script" happens at each pass of the loop.)

- In "silent mode", when you add a hash sign # at the end of a calculation line (a space before # is needed) -- see below.

Silent mode and accumulation mode only apply to the specific calculation line.

 

Note that only calculation lines have "results." Variable assignment commands 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 always open hy in an external editor (by default notepad.exe) with the command EDIT, which is short for EDIT hy.

(Close the file in the editor, or close the editor, before the next calculation. What happens if you don't depends on the editor.)

 

Silent Mode

In case that you do not want the result of a calculation to be written to hy, you can use silent mode by adding the hash sign at the end of the calculation line.

? 2 3 * #

After the above line the value of $ will be 6, but the content of hy will still be what it had been before.

It can be important to use silent mode in loops, particularly loops with more than a few passes, because writing results to hy at each pass is a time-consuming process.

Note that this use of the hash sign at the end of a calculation line is unrelated to using the hash sign for comments.

 

Accumulation Mode

There is a lot more to the result file hy than we have seen so far.

A major feature of Hypatia is that you can "accumulate" results -- this means that a new result does not overwrite the content of hy, but gets appendeded to it.

 

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 (the four products are calculated one by one, then the four results are added up with the n-argument operator SUM):

? 2 1.5 * 4 3 * 5 3 * 6 4 * SUM

= 54

 

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 required.)

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 (unless it has more than 40 lines or 4000 characters, see above).

? 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 new result overwrites the data in hy. If you want to keep them (maybe for further calculations, like their mean value), you have two options:

You can use silent mode:

? (hy) SUM #

Then afterwards you can calculate the mean:

? (hy) MEAN

Or you can 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 neglecting to use silent mode:

? @rooms SUM

? @rooms MEAN

 

This has been a very simple example. We will return to it in 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 has a much wider range of uses.

 

Within a script (that is, before the script ends) hy only gets updated by calculation lines that use accumulation mode -- more about that in chapters "Scripts" and "Loops".

 

Line Breaks in hy

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 to 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

 

&& on its own is a command that inserts a line break in hy.

If hy is empty, both ways of inserting a line break (&& at the end of a calculation, or && as a command) are ignored.

 

Home, Up: Results, Next: Result Commands