Next: Functions, Previous: Expressions And Statements, Up: aime [Index]
aime statically typed character has its merits, but it is hardly accommodating towards conveying data of different types over the same interface, and that in turn is not easily avoidable at all times.
There are available general purpose solutions that seemingly break the language character and they include the use of the aime heterogenous collections (‘list’, ‘record’, etc). Data may be added to convenience collections and the collections passed instead, with the values and types preserved for the interested parties.
A perhaps more convenient solution is the use of variadic functions. The functions allow for extra arguments of unspecified number and type. Variadics were nonetheless not designed to help with going around static typeness and for that reason they are most of the type a too big solution to the problem.
Typeless anonymous arguments functions were designed specifically to offer an option to creating type oblivious interfaces. Like variadic functions, they allow arguments of unspecified type. Unlike for variadics, the number of the arguments is fixed.
Both variadic and typeless anonymous arguments functions are solutions of limited use, as they only address passing arguments to functions. And accessing the unnamed arguments calls for the ‘object’ type, though it would have been possible to avoid the call.
The other solution to avoiding the rigors of the statically typed system is the ‘object’ type. Very similar to the heterogenous collection solution, the ‘object’ type one is of more general use than the unnamed argument function one, and between the two with respect to conspicuousness.
The ‘object’ type is a single slot, always full container. It records data of any type together with its type. Its operating interfaces are simpler than those of the general use heterogenous collections, and further simplified by implicit convertions between the ‘object’ type and the other data types. The type is a light weight one, at least when compared with the proper collections, and its use incurs a lot smaller cost than that of collections. The downside of that is that the ‘object’ type is in some respects an improper data type, one that cannot be used where others can.
The ‘object’ type is not a declarable type. Function variables of the ‘object’ type cannot be declared, though function arguments may be of the ‘object’ type, just as the function returns can be. The heterogenous collections will not record data of the ‘object’ type, though they will record data described by ‘object’ data.
void object_1(object a, object b, integer c) { }
The function ‘object_1’ takes three arguments, the first two of the ‘object’ type, in effect of any type, the last of the ‘integer’ type.
object object_2(void) { return 3; }
The function ‘object_2’ returns 3 as an ‘object’ value.
object object_3(list l, integer (*f)(object)) { integer i; i = 0; while (i < l_length(l)) { if (f(l_query(l, i))) { break; } i += 1; } return l_query(l, i); }
The function ‘object_3’ searches the ‘l’ list until it finds data that passes the ‘f’ test (‘f’ is a pointer to function evaluating as ‘integer’ and taking one argument of the ‘object’ type) and returns the found data. If there’s no data matching the criteria, the function does not return.
See Errors.
See Function Pointers.
Next: Functions, Previous: Expressions And Statements, Up: aime [Index]