It is straightforward to make calls to external functions in ATS. For instance, the following code demonstrates a typical way to do so:
local extern fun __fprintf : (FILEref, string(*fmt*), int, int) -> int = "mac#fprintf" in (* in of [local] *) // val N = 12 val _ = __fprintf (stdout_ref, "fact(%i) = %i\n", N, fact(N)) // end // end of [local]
There is also built-in support for calling external functions in ATS directly. For instance, the following code does essentially the same as the code presented above:
When $extfcall is employed to make an external function call, its first argument is the return type of the call, and its second argument is the name of the called function (represented as a string), and its rest of arguments are the arguments of the called function.