nap command
expr command produces a single (scalar) number.
For example:
% expr "2 * 3.5" 7.0Note that the Tcl result of this command is simply the text "
7.0".
However the nap command often produces an array containing millions of numbers.
It is not practical to store, process and display millions of numbers as text.
It is far better to store and process them in binary form.
The binary values are
stored in a memory object called an N-dimensional Array Object (NAO), which
also includes other information such as the number of elements and the data-type.
NAP is designed to efficiently handle large arrays, but let us begin demonstrating it on
the above simple scalar expression:
% nap "2 * 3.5" ::NAP::16-16What is this strange Tcl result "
::NAP::16-16"?
It is the ID of the NAO result and
also the name of the command that is used to examine the NAO and make changes to it.
Such a command is called an Object-Oriented Command (OOC).
The ID is called the OOC-name.
Continuing the above example, let's execute the OOC by typing its name
"::NAP::16-16":
% ::NAP::16-16 7This displays the value in the NAO.
However the following attempt to repeat the command fails because the NAO and its associated OOC were automatically deleted at the end of the first execution of the OOC. NAP detected the fact that this NAO was not referenced by anything and it was therefore treated as use once and then discard.
% ::NAP::16-16 invalid command name "::NAP::16-16"
Tcl syntax allows a command to include another command within square brackets [].
First the bracketed command is executed and its Tcl result replaces it.
Then the modified whole command is executed.
So the above commands can be simplified by enclosing the nap command in brackets
as follows:
% [nap "2 * 3.5"] 7
NAP expressions can contain the assignment operator "=" with a Tcl
variable name on its left and any expression on its right.
For example:
% nap "result = 2 * 3.5" ::NAP::24-24The following shows that this sets the Tcl variable
result to the string value
"::NAP::24-24".
% set result ::NAP::24-24Tcl syntax replaces "
$name" by the contents of variable
name.
So in our example "$result" is replaced by
"::NAP::24-24", as shown in the following:
% $result 7The fact that this NAO is referenced by something (the variable "
result")
means that it is not deleted after it executes.
So we can repeat the command:
% $result 7We can also use variable names within NAP expressions. For example:
% [nap "result + 4"] 11Note that no "
$" is needed before variable names in NAP expressions.
Variables can also contain numeric strings, as in:
% set offset 8.2 8.2 % [nap "result + offset"] 15.2
An OOC can have arguments.
The following example demonstrates the argument all,
which requests additional information about the NAO.
% $result all ::NAP::24-24 f64 MissingValue: NaN References: 1 Value: 7
The following additional information is provided:
::NAP::24-24
f64 (64-bit floating-point)
NaN (special value for missing data)
1 because
there is one variable (result) pointing to this NAO.
If it were 0 the NAO would be deleted.