Great Data Types in Author
- Tutorial
In the interpreter “Author”, there are three data types that are different from other, classical, languages, which I want to talk about in this article, namely “digit”, “graf” and “program”. They are responsible, respectively, for astronomical numbers without a floating point, a universal graph, and a tree of operators and function calls with variables and constants.
The following example demonstrates the main difference between the digit type and the int type.
In the first case, the calculation went right. In the second there was an overflow of memory for type "int". In the third, the calculation went smoothly. This happened because the “digit” type can allocate memory for the exponent of a number as necessary. For the number mantissa, a restriction should be specified to avoid memory leak when dividing, say, by three. Method like "x.setAccuracy (63);" indicates the limitation of the mantissa number in decimal places. The type has other useful methods.
Now I will tell a little about the universal graph. A graph refers to many nodes and the connections between them. For the “graf” type, a node exists only when it has at least one connection. Each link has two node numbers, the corresponding value of the presence of input arrows and the name of the link. In addition to connections between nodes, in a universal graph, there is also a connection between a node and a marker. A marker is a line of text. Each marker link has one node number, a link name, and a marker name. There are also logical values about the presence of an input arrow in the node and in the marker.
The following program demonstrates the capabilities of a universal graph.
To create a variable of type “graf” you need to use the cast operator. Next, we set the graph itself with a shape similar to an open envelope. The “G.getMARKER (0, #, #, 0, #)” method searches the links of the node with the marker for the given mask and returns an array of the elements found. Each element is an array with the data requested in the mask. The search mask must contain at least one unknown link detail, which is indicated by the “#” symbol. In the language "Author", the symbol "#" returns the value "void", which can be obtained, for example, from a function without "return". The ".export ()" array method will convert nested arrays to a string. The trace () function displays a string on the screen. The graph method “G.getNET (4, #, #, #, #)” searches for links between the nodes of the graph, taking into account the symmetry of the search and works similarly to finding links with markers.
And that turns out to be a program that seeks ways of traveling "around the world."
A graph type also has other useful methods.
To illustrate the possibilities of the fundamental type of "program" I will give the following example.
The first line of the function algorithm indicates the terminal branch of the recursion. Next, the variable "f" gets access to the function in which it is located. Then the variable “pos” receives the unique identifier of the last node in the (block) diagram of the algorithm into which the function turned at the time of execution. The last node is above the zero node. Next, we get copies of the command located in the last node of the algorithm scheme. Actually, the “team” is an object of the “program” type. It is a tree of operators and function calls with variables and constants. Any command can be either converted to text or executed. Using a method like “command.getSub ({})”, you can copy a branch from a tree by specifying an access path, in this case the whole tree is copied.
The “PROGRAM ()” function converts a line of program text to the type “program”.
The type has other useful methods.
more | Followed by.
The following example demonstrates the main difference between the digit type and the int type.
// fact.txt
var fact (n) {return n <2? 1: n * fact (n-1);}
void main () {
trace (fact (10));
trace (fact (50));
trace (fact ((digit) 50));
x = (digit) 1;
x.setAccuracy (63);
trace (x / 3.123);
getstring ();
}
3628800
0
30414093201713378043612608166064768844377641568960512000000000000
0.320204931155939801472942683317323086775536343259686199167467178
In the first case, the calculation went right. In the second there was an overflow of memory for type "int". In the third, the calculation went smoothly. This happened because the “digit” type can allocate memory for the exponent of a number as necessary. For the number mantissa, a restriction should be specified to avoid memory leak when dividing, say, by three. Method like "x.setAccuracy (63);" indicates the limitation of the mantissa number in decimal places. The type has other useful methods.
Now I will tell a little about the universal graph. A graph refers to many nodes and the connections between them. For the “graf” type, a node exists only when it has at least one connection. Each link has two node numbers, the corresponding value of the presence of input arrows and the name of the link. In addition to connections between nodes, in a universal graph, there is also a connection between a node and a marker. A marker is a line of text. Each marker link has one node number, a link name, and a marker name. There are also logical values about the presence of an input arrow in the node and in the marker.
The following program demonstrates the capabilities of a universal graph.
// UniversalGraf.txt
void main () {
// Set the graph (envelope).
G = (graf) 0;
G.NET (0.1, "expensive", 1.1);
G.NET (0.1, "expensive", 1.4);
G.NET (1.1, "", 1.2);
G.NET (1.1, "", 1.4);
G.NET (1.1, "", 1.3);
G.NET (2.1, "", 1.3);
G.NET (2.1, "", 1.4);
G.NET (3.1, "", 1.4);
G.MARKER (0,0, "", 0, "Mars");
G.MARKER (1.0, "", 0, "Vinnitsa");
G.MARKER (2.0, "", 0, misto = "Gayvoron");
G.MARKER (3.0, "", 0, "Moscow");
G.MARKER (4.0, "", 0, "Gaysin");
G.MARKER (0,1, "life", 0, "no");
trace (G.getMARKER (0, #, #, 0, #). export ());
trace (G.getNET (4, #, #, #, #). export ());
tracex (misto);
stop = n = G.getMARKER (#, 0, "", 0, misto) [0] [0];
do {
tracex ("->");
n = G.getNET (n, #, #, 1, #) [#] [2];
tracex (G.getMARKER (n, 0, "", 0, #) [0] [0]);
} while (stop! = n);
getstring ();
}
{{0, "", "Mars"}, {1, "life", "no"}}
{{1, "expensive", 1,0}, {1, "", 1,1}, {1, "", 1,2}, {1, "", 1,3}}
Gayvoron -> Moscow -> Vinnitsa -> Moscow -> Gaysin -> Gayvoron
To create a variable of type “graf” you need to use the cast operator. Next, we set the graph itself with a shape similar to an open envelope. The “G.getMARKER (0, #, #, 0, #)” method searches the links of the node with the marker for the given mask and returns an array of the elements found. Each element is an array with the data requested in the mask. The search mask must contain at least one unknown link detail, which is indicated by the “#” symbol. In the language "Author", the symbol "#" returns the value "void", which can be obtained, for example, from a function without "return". The ".export ()" array method will convert nested arrays to a string. The trace () function displays a string on the screen. The graph method “G.getNET (4, #, #, #, #)” searches for links between the nodes of the graph, taking into account the symmetry of the search and works similarly to finding links with markers.
And that turns out to be a program that seeks ways of traveling "around the world."
A graph type also has other useful methods.
To illustrate the possibilities of the fundamental type of "program" I will give the following example.
// demo.txt
var main (nirvana, paradise, skazka) {
if (isset (nirvana)) return paradise + nirvana + skazka;
f = getFunction (getThisFunctionName ());
pos = f.Up (f.Root ());
command = command2 = f.getCommand (pos);
trace ((string) command + "==" + eval (command));
trace (command.getSub ({}));
trace (command.getSub ({0}));
trace (command.getSub ({0,0}));
trace (command.getSub ({0,1}));
trace (command.getSub ({1}));
trace ("-----------------");
pos = f.Up (pos);
command = f.getCommand (pos);
trace ((string) command + "==" + eval (command));
trace (command.getSub ({}));
trace (command.getSub ({0}));
trace (command.getSub ({0,2}));
trace (command.getSub ({0,4}));
trace (command.getSub ({0,4,0}));
trace (command.getSub ({0,4,3}));
trace (command.getSub ({0,4,3,0}));
trace (command.getSub ({0,4,3,1}));
trace (command.getSub ({1}));
trace ("-----------------");
proga = PROGRAM ("X = # + #");
trace (proga);
proga.setSub ({1,0}, command);
proga.setSub ({1,1}, command2);
trace (proga);
eval (proga);
trace ("X ==" + X);
getstring ();
return
{0,1,2,3, main (100,20,7-3)} [4];
(1 + 9) * 100;
}
(1 + 9) * 100 == 1000
(1 + 9) * 100
1 + 9
1
9
100
-----------------
{0,1,2,3, main (100,20,7-3)} [4] == 124
{0,1,2,3, main (100,20,7-3)} [4]
{0,1,2,3, main (100,20,7-3)}
2
main (100,20,7-3)
main
7-3
7
3
4
-----------------
X = # + #
X = {0,1,2,3, main (100,20,7-3)} [4] + (1 + 9) * 100
X == 1124
The first line of the function algorithm indicates the terminal branch of the recursion. Next, the variable "f" gets access to the function in which it is located. Then the variable “pos” receives the unique identifier of the last node in the (block) diagram of the algorithm into which the function turned at the time of execution. The last node is above the zero node. Next, we get copies of the command located in the last node of the algorithm scheme. Actually, the “team” is an object of the “program” type. It is a tree of operators and function calls with variables and constants. Any command can be either converted to text or executed. Using a method like “command.getSub ({})”, you can copy a branch from a tree by specifying an access path, in this case the whole tree is copied.
The “PROGRAM ()” function converts a line of program text to the type “program”.
The type has other useful methods.
more | Followed by.