Int4 Aster Documentation

Tables and dynamic symbols

Dynamic symbols

Dynamic symbols enable calling functions and variables by using a string representing their respective names. Using the {} syntax requests the evaluator to consider the result of evaluating the expression between {} and then applying the name to refer a function or a variable.

Examples

f="poWER";X=2;{F}({"x"},3)              # evals to 8 - calls function named "POWER"
{"A"}                                   # evals to variable A
{"A"} = 5                               # variables addressed dynamically can be assigned to

Tables and lists

Variables in ASTER can contain representations of lists and tables, commonly referred to arrays or multi-dimensional arrays in well-known programming languages.

The data is stored as pairs of keys and values, where keys are used to index data stored in a list or a variable. Keys can be numeric or literal (represented as strings, e.g. A[1]["KEY"]).

Helper functions

COUNT(x) function may be used for obtaining the number of elements in a list or given dimension of the table.

In order to list all the keys of a list or given dimension of the table, the INDEXES(x) function may be used, which returns the list, in arbitrary order.

In case a value (or a complete dimension) needs to be removed, use the UNSET(x) function, providing the variable or element declaration as parameter.

Appending data to list

It is possible to easily append elements to lists, using the , operator. The operator will add the element with a new index, being equal to current count of elements plus one.

Examples

Simple usage
A=(1,2,3,4);                            # list (one dimensional array)
B=A;                                    # assignment copies values
A[2]=5;
NOT (A[2] == B[2]) AND A[3] == B[3]     # evals to true - A[2] is not equal to B[2]
Removing elements
A=(1,2,3,4);
UNSET(A[2])                             # A is now (1,3,4)

# note that unset does not alter indexes, that is : A[1] == 1, A[3] == 3, A[4] == 4
Multiple dimensions
RECORD=("John", "Smith"); A[1] = RECORD;
RECORD=("Thomas", "Black"); A=(A, RECORD);
RECORD=("Adam", "Green"); A=(A, RECORD);

# finding the first name of Mr. Black
I=0; 
WHILE(I<COUNT(A),
   IF(A[I=I+1][2] $== "Black", 
       BREAK(A[I][1])))
# loop will break returning "Thomas"
Appending elements
A=1;
A=(a,"B");
A=(a,"C");
A=(a,"E");

# now A is equal to A=(1,"B","C","E")

B=A;
A=(A,"F");
B[COUNT(B)+1] = "F";

# now both lists A and B are equal, containing 5 elements, (1,"B","C","E","F")
Listing all elements of list in arbitrary order
DEFUN("PRINTLIST2",("LIST"),
  LOCALS(("I","R","J"),
    FOR(I=1;R="";J=INDEXES(LIST),I<=COUNT(J),I=I+1,
        (R=R&LIST[J[I]]&","));
        "[" & SUBSTR(R,0,-1) & "]"
));

A=(1,2,3,4);
PRINTLIST2(A)                         # will evaluate to [1,2,3,4]