If a sequence
~c (tilde, followed by some character) is
found, the format/3
and friends first check whether the user has defined a predicate to
handle the format. If not, the built-in formatting rules described above
are used. Char is either a character code or a one-character
atom, specifying the letter to be (re)defined. Head is a
term, whose name and arity are used to determine the predicate to call
for the redefined formatting character. The first argument to the
predicate is the numeric argument of the format command, or the atom
if no argument is specified. The remaining arguments are filled from the
argument list. The example below defines
~T to print a
timestamp in ISO8601 format (see
The subsequent block illustrates a possible call.
:- format_predicate('T', format_time(_Arg,_Time)).
format_time(_Arg, Stamp) :-
format_time(current_output, '%FT%T%z', Stamp).
format('Now, it is ~T~n', [Now]).
Now, it is 2012-06-04T19:02:01+0200
Now = 1338829321.6620328.