Simple example of using special sequence @
with format/2.
@
Interpret the next argument as a goal and execute it. Output written to thecurrent_output
stream is inserted at this place. Goal is called in the module calling format/3. This option is not present in the original definition by Quintus, but supported by some other Prolog systems.
File: example.pl
format_example :-
List = [1,a,'B',3.14,"Hello"],
format('~@',[print_list(List)]).
print_list([H|T]) :-
format(' ~k~n',[H]),
print_list(T).
print_list([]).
Demonstration
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.27-24-g44c2d0e2d)
?- working_directory(_,'C:/Users/Groot').
true.
?- [example].
true.
?- format_example.
1
a
'B'
3.14
"Hello"
true.
Some real world examples: