This library defines basic I/O functions and other common functions. Almost every program you write will need at least one of the functions in this library.
external unit print (...)
This function allows you to print to the terminal (standard
out). It returns unit, and so should not be used in assignments. It takes any number of
arguments of any type, converts them to strings and prints them, one after the other. String
arguments may contain standard escape sequences, like n and
t
(newline and tab). This is similar to the UNIX printf function, which print actually
uses to print strings.
external bool input_ready ()
This functions takes no arguments and returns true if and
only if a key has been pressed, but not read from the keyboard. More exactly, it returns true
if and only if the standard input buffer is nonempty.
external string get_char ()
This function takes no arguments and waits for the next key to be
pressed. It returns a length 1 string with the ASCII representation of the key pressed. To be used
in a non-blocking sense, guard the function with input_ready.
external unit exit ()
This function kills ccli.
external int atoi ( string )
This function converts its argument, which is supposed to be
a string representation of an integer, into an int.
external real atof ( string )
This function converts its argument, which is supposed to be
a string representation of an real, into a real.
external string tostring ( 'a )
This function takes an argument of any type and converts
into a string.
external int uclock (), mclock (), dclock ()
These functions return the number of
microseconds, milliseconds and seconds, respectively, since ccli was started.
Here is an example program that uses all three time functions.
include standard.ccl program main() := { print ( "Press any key to print the clock values\n" ); input_ready() : { get_char(), print ( "\rms = ", mclock(), ", us = ", uclock(), ", s = ", dclock(), " \r" ) } };
external unit usleep ( int )
Sleeps for the number of microseconds specified by its
argument. Note that this may not be especially accurate in a multitasking operating system like
UNIX.