Pseudo Constants

Home, Up: Operators and Constants

 

In Hypatia's syntax pseudo constants appear like constants, even though their values are not constant at all. Like constants, they can be seen as zero-argument operators.

 

On this page:

Pseudo constants RAND, DUP, I, ISLOOP, TIME.

 

Pseudo Constant RAND

RAND returns a random floating point number in the range of 0 to 1.

Unlike RANDINT and RANDND, which are 2-argument operators, the pseudo constant RAND does not have an argument.

 

Pseudo Constant DUP

DUP duplicates the closest number, constant or variable to its left before any calculation is done, which allows this value to be used in a calculation twice.

A simple example:

4 SQ DUP + = 20

(DUP has the value of 4, the closest number to its left, not 16!)

When there is no number, constant or variable to the left of DUP in the input line, then DUP has the value of the most recent calculation result, the variable $.

You can use DUP several times in one calculation line, referencing the same or different values.

The pseudo operator WHISK is a more powerful alternative to DUP.

DUP can be used in user-defined operators, which will be discussed in the context of user-defined elements.

 

Pseudo Constant I

I is the loop index in a DO loop.

In a REPEAT n loop I is the loop index plus 1.

Outside of loops the loop index I is always 1.

Regarding loops see chapter "Loops".

Even though I is not a variable, you can display its current value with SHOW I.

 

Pseudo Constant ISLOOP

ISLOOP can be used in scripts to determine whether the script is called in a loop or not.

In a DO or REPEAT n loop ISLOOP is 1, outside of a loop (when the script is called directly) ISLOOP is zero.

Regarding loops see the respective chapter.

 

Pseudo Constant TIME

In a DO or REPEAT n loop TIME is the time in seconds since the start of the loop.

Outside of loops TIME is always zero.

In loops with large numbers of passes (Hypatia's maximum is 10 million) you can use TIME to measure and optimize the time a script needs, to display status messages at given intervals, or to end a loop after a specified amount of time has elapsed.

Even though TIME is not a variable, in a loop you can display its current value with SHOW TIME.

Regarding loops see chapter "Loops".

 

Home, Up: Operators and Constants, Prev: Constants, Next: Pseudo Operators