next up previous index
Next: Arrays Up: Interface to Externals Previous: Strings

I/O in External Predicates

ECLiPSe provides the user with the ability to perform i/o on its predefined streams as well as on the dynamically opened ones. ECLiPSe stream identifiers which correspond to the predefined streams are

Current_Input  

Current_Output  

Current_Error  

Toplevel_Input  

Toplevel_Output  

Answer_Output  

Debug_Input  

Debug_Output  

These are C variables of type stream_id. Other streams can be passed to the external predicates in the same way as to builtins that accept stream specifications. Such a stream specifications must then be converted into a C variable of the type stream_id by using the macro
p_example(sval, stag)
value sval;
type  stag;
{
    stream_id stream;
    Get_Stream(sval, stag, OUTPUT, stream)
    ...
}
where the third parameter specifies if the stream must be open for INPUT or OUTPUT.

There are two main functions to perform i/o on Prolog streams: formated printing in the usual C way is done by

Fprintf(stream, format, arg1, arg2, ...)
  is similar to fprintf(3) in that its first argument is a stream identifier, the second one is a string which specifies the format in the style of printf(3) and the rest is a variable number of arguments to be printed.

Prolog terms can be output with the function

Write(val, tag, stream)
  which outputs the term with tag tag and value val on the specified Prolog stream. For example
Fprintf(Current_Output,
        "tag = %d, value = %d\n", tag.kernel, val.nint);
Write(val, tag, Current_Output);
are two ways how to print a Prolog integer number; the output looks like
tag = 5, value = 1
1
footnote Be aware that you can not rely on a specific coding of a ECLiPSe tag! Similarly, the macro
Writeq(val, tag, stream)
  has the effect of writeq/2.



next up previous index
Next: Arrays Up: Interface to Externals Previous: Strings



Micha Meier
Mon Mar 4 12:11:45 MET 1996