ACON
Home/Topics |
Commands
ACON is user programmable, enabling:
- a range of parameter choices for the visualization tools,
- automation of multiple plot creation,
- substitution of some primitive operations with user code.
The program contains a compiler and interpreter for
a "virtual machine" based on an enhanced version of
Extalk (see David Betz, 1988. Some Assembly Required - Embedded Languages, BYTE Nov. 88, pg. 409-416).
The programming features include:
Functions,
Multiple Statement Functions,
Global Variables,
Local Variables,
Begin End,
While do,
If then else,
Assignment,
Arithmetic,
Parenthesis,
Boolean operators,
Return,
Exit,
Erase Function,
Erase Variable,
ValueOf,
Object Type, and
DLL Cmd.
Additional commands are primarily used while creating scripts. They include:
Assign.
The script keyword Function begins the definition of a new
user-definable function. A function may have 0 or more
parameters declared as arguments. The arguments to functions are
not data-typed (ie. integer, real, etc.), but rather, all objects defined during execution are
self-typed. If a command or function is passed an argument type
it is not able to use, an error will be generated. All functions
will return either no result or a single data object as a result.
This example function takes no parameters, and returns
no result to the interpreter:
Function showtime() { print("The time now is
",ctime(time())): };
Once the function has been defined (psuedo-compiled)
by executing the function definition, the function may be executed
as if it were a built-in ACON function.
showtime();
The time now is Sat Oct 17 20:09:57 1992
If a function has no parameters (as above), it may
be called without the parentheses. Additionally, the semi-colon
at the end of a command line is also optional if the line is not
itself within a function definition.
showtime
The time now is Sat Oct 17 20:09:57 1992
Functions containing more than 1
executable statement require the statements to be bracketed by
{ } or Begin ... End, and may be terminated by semi-colons for clarity.
Function marker(x,y,size) {
objstart("triangle marker");
draw(x - size, y - size,0);
draw(x+ size, y - size,1);
draw(x, y + size,1);
draw(x - size, y - size,2);
objend("triangle marker");
exit;
};
See the example User-defined Functions
Variables are defined using the = operator (see Assignment). By default, all variables are global variables, and once defined, are remain available while ACON is running, until reassigned.
a = 5;
print(a * 10);
50
Local variables are defined by preceding the name of the variable with a $. Local variables are only available within an executing function, and are removed from memory when the function exits, unless the local variable is returned by the function as the parameter of the return() command. This behaviour may be altered using the Local_Variables command.
Function ynorm(mn,sd) {
/* returns normal variates the shape of mn */
$t = shape(len(mn),1.); /* $t is a local variable */
ynormz = mn + sd * sqrt((-2. * log(rand($t)))) * cos(pi * 2. * rand($t));
return(ynormz);
};
These script keywords delimit
multiple statements to group them into a single logical statement.
These may be substituted with "{" and "}"
respectively.
For example the "then" clause requires
a single logical statement.
...
if (x > 10) then
Begin
Data_Window(-67.5, -66.0, 42.1,44.0);
Data_viewport(inches(1),inches(5),inches(3),inches(8));
End;
These script keywords provide
a conditional looping control structure. The do loop body statement
will be executed while the test statement is evalutated as TRUE. The do keyword is optional
Function test()
{ while (x < 10) do
BEGIN
Data_Window(-67.5, -66.0,42.1,44.0);
Data_viewport(inches(1),inches(5),inches(3),inches(8));
END;
};
See the example User-defined Functions
Conditional execution. These script keywords provide
a conditonal execution of the 1st or 2nd conditional statement. The else keyword and 2nd condition is optional.
if (x > 10) then
{
Data_viewport(inches(1),inches(5),inches(1),inches(5));
Data_Points(mat);
}
else
{
Data_viewport(inches(1),inches(5),inches(5),inches(10));
Data_Points(mat);
};
Assignment. This script keyword assigns the 2nd operand
to the 1st operand which must be a new or existing named object.
x = 36 + 5.5;
(Note this operator was ":=" in versions
4.35 and earlier)
These script keyword take 2 operands and returns
a result. The operands may be scalars, vectors, or matricies (logically
some combinations of operands of different rank will not work).
To add:
x = 36 + 5.5;
x
41.5
To subtract:
x = 36 - 5.5;
x
30.5
To divide:
x = 36 / 5.5
x
6.54545
To multiply:
x = 36 * 1 2 3 4 5;
x
36 72 108 144 180
Short forms of these operators exist ( += -= *= /=):
/* To increment a value by a fixed amount */
x = 5;
x += 10;
print(x);
15
As well, a simple increment by 1 operator exists (in contrast to the C language, this is a prefix operator, it operates before any other operations in a sequence):
/* Increment x by 1 */
x = 10
print(3 * x++);
33
See the example User-defined Functions
Parentheses. These script keywords enclose script
keywords to define execution sequence.
x = 36 * (5.5 + 6)
x
414
The logical comparison operators are:
| Less than |
< |
| Less than or equal |
<= |
| Equal |
== |
| Greater than or equal |
>= |
| Greater than |
> |
| Not equal |
!= |
| And |
&& |
| Or |
|| |
| Not |
! |
These script keywords compare
2 numeric or string operands and return the boolean result true
or false. The global boolean variables true and false are available to be used for assignment or comparison with boolean operations.
if (x > 10)
{
if (y == 10)
{ Data_Viewport(inches(1),inches(5),inches(1),inches(5));
Data_Points();
};
};
x = true
y = false
if (x) print("X is true")
X is true
if (!x) print("X is false")
if (y) print("Y is true")
if (!y) print("Y is false")
Y is false
if (!(y && x)) print("Not both true")
Not both true
(Note: "==" was "=" in versions
4.35 and earlier)
See the example Multiple Plots
Return from function. This script keyword
allows the return from within a function, returning the single parameter, on the stack. Since version 8.00, functions DO NOT return data unless an explicit Return(xxx) command is executed (otherwise a NIL is returned).
- There is 1 parameter:
- object - the object to be returned from this function, usually a scalar, vector or matrix.
Function test(x)
{ if (x > 10) then
{ return(1);
}
else
{ return(0);
};
};
Exit from function. This script keyword
allows the exit from within a function without altering the current
execution stack. This is used when the extalk interpreter is recursively
called from within executing built-in C functions. An example
of this is when the user-defined function marker is executed from
within the Data_Points function. The Marker
function should end with a exit keyword.
/* a user-defined marker function */
Function marker(x,y,size)
{ /* triangle marker */
draw(x, y + (0.5 * size),0);
draw(x - (0.5 * size), y - (0.5 * size),1);
draw(x + (0.5 * size), y - (0.5 * size),1);
draw(x, y + (0.5 * size),2);
exit;
};
Erases a function from memory.
- There is 1 parameter:
- function name - the name(s) of any exisiting user-defined
function(s) . To erase multiple functions, a blank separated string
of names, or a character matrix may also be supplied with 1 function
name per row of the matrix.
Erase_Function("function name");
Erase_Function("MyFunc");
Erases a variable from memory.
- There is 1 parameter:
- variable name - the name of any exisiting user-defined
variable. To erase multiple variables, a blank separated string
of names, or a character matrix may also be supplied with 1 variable
name per row of the matrix.
Erase_Variable("variable name");
Erase_Variable("MyVar");
Returns the value of the named object.
- There is 1 parameter:
- object - the name of the object for which a value is to be returned.
value = ValueOf("objectname");
a = 1 2 3;
b = ValueOf("A");
print(b);
1 2 3
// Note that when you know the name of the source object, this is equivalent to:
b = a;
Returns the type of an object as an integer. The
possible returned types are:
0 - @TYPE_NIL - null
3 - @TYPE_STRING - string
4 - @TYPE_BOOLEAN - boolean
7 - @TYPE_FILEPTR - file ptr
8 - @TYPE_INTEGER - integer
9 - @TYPE_DOUBLE - real
10 - @TYPE_INTEGER_VECTOR - integer vector
11 - @TYPE_DOUBLE_VECTOR - real vector
12 - @TYPE_INTEGER_MATRIX - int matrix
13 - @TYPE_DOUBLE_MATRIX - real matrix
14 - @TYPE_INTEGER_MATRIX_3D - integer 3D matrix
15 - @TYPE_DOUBLE_MATRIX_3D - real 3D Matrix
16 - @TYPE_CHARACTER_MATRIX - char matrix
17 - @TYPE_CHARACTER_MATRIX_3D - char 3D matrix
18 - @TYPE_OBJECT_VECTOR - enclosed vector of objects
20 - @TYPE_PICTURE - bitmap
The type of object can be compared to built-in variables representing the object types e.g. @TYPE_NIL (above).
- There is 1 parameter:
- object - the object to be queried for its type.
value = Object_Type(object);
Object_Type(1 2 3);
10
x = "test";
Object_Type(x);
3
Object_Type(x) == @TYPE_STRING;
true
Dynamically loads and executes a DLL.
- There are 3 or more parameters:
- fname - name of DLL file to load. Use Active_Dir to set the active
directory to the directory containing the DLL.
- entryname - name of DLL entrypoint to execute.
- flags - Dynacall flags giving the type of call and type of result.
- args - an optional acon variable or address(variable) as required to 'feed' the DLL.
res = DLL_Cmd(fname,entryname,flags [,args...]);
Note: res may be meaningless if not returned by the DLL.
/* Call MS Visual C runtime library to compute sin(3.1415) */
//flag DC_MICROSOFT 0 0x0000 /* Default */
//flag DC_BORLAND 1 0x0001 /* Borland compat */
//flag DC_CALL_CDECL 16 0x0010 /* __cdecl */
//flag DC_CALL_STD 32 0x0020 /* __stdcall */
//flag DC_RETVAL_MATH4 256 0x0100 /* Return 4 byte value cast as an integer */
//flag DC_RETVAL_MATH8 512 0x0200 /* Return 8 byte value cast as a double */
x = 3.1415;
r= DLL_Cmd("msvcrt.dll","sin",512+16,x);
print(r)
9.26536E-005
Dynamically assign a object given a name. This is useful in cases where
the name of the object to be created is unknown until execution time.
- There are 2 parameters:
- objname - name of object to be created.
- object - the object which is assigned to this name.
Assign(objname,object);
// Assign the result of a calculation to 'A'
name = "A";
assign(name,3 * 4);
// Note that this is equivalent to A = 3 * 4
ACON
Home/Topics |
Commands
|