Previous: , Up: Language Miscellanea   [Index]

12.4 Function Pointer Data Structure Retrieval

The data structures provided by the libaime libraries are heterogenous structures, storing data of any type. Function pointer data is included.

See Libraries.

For some of the supported data types, the libraries interfaces may include specific store and retrieval functions. For an instance, the list library objects does describe special intrinsic integer functions.

See The List Library.

Appending to the:

    list l;

one -1066 integer may be coded as:

    lb_p_integer(l, -1066);

Retriving the integer in the last position as:


See Data Type Specific List Functions.

The same may be achieved through type generic interfaces:

See Data Type Generic List Functions.

    l_append(l, -1066);



Function pointers may be stored with ‘list’ objects, yet only through type generic interfaces:

See Function Pointers.

    l_append(l, pow);

Retrieve data in the last position as:




See Negative Indices.

Only data has now type ‘object’ and implicit conversion are performed for function parameters only. Which leads to one method of restoring the function pointer nature of data: pass data as function argument, reclaim it as function return.

real (*f1(real (*fp)(real, real)))(real, real)
    return fp;

The function hinted by the stored function pointer may be called as:

    f1(l_back(l))(3, 4);

If a function pointer / function pointer assignment operator has beed defined, the

    real (*fq)(real, real);

function pointer may be assigned as:

    fq = f1(l[-1]);

and called as:

    fq(5, 4);

It may be even set as:

    f2(fq, l_back(l));

by some function setting its reference function pointer parameter, such as:

f2(real (*&fz)(real, real), real (*fs)(real, real))
    fz = fs;

A generic setter function like:

    set(0, $1);


f4(&, object o)
    set(0, o);

may be used to set function pointers from data structure retrieved ‘object’s:

    f3(fq, l_back(l));

If a function pointer / object assignment operator has beed defined, the function pointer may be set as:

    fq = l[-1];

The function hinted by the stored function pointer may be called by some function via its function pointer parameter.

f5(real (*fp)(real, real))
    return fp(7, 4);

Call as:


Functions, including those hinted by pointers stored with data structures, may be called via generic function callers, like the ‘call’ interface provided by the trap library.

See The Error Library.

call’ takes as arguments a function pointer and the arguments for the function call:

    call(l_back(l), 11r, 4r);

or leaving some implicit convertions for ‘call’ to perform:

    call(l[-1], 11, 4);

Previous: , Up: Language Miscellanea   [Index]