Basic output
A format query is supported that works much like format in lisp, but using
~w instead of ~A and ~n instead of ~%, and providing all arguments in a list, e.g.
format('X is ~w, Y is ~w ~n', [X,Y]).
Many special characters and format options are available, see the manual page for details.
Another basic way of writing to standard output is writing terms or single characters. Two versions of term writing are provided, one of which adds a newline after the output. There are also built-in output functions that write a special character to standard output, such as newlines, tabs, etc.
The set of built-in output functions include:
write(Term), write_ln(Term), put(Char), nl, tab, flush
You'll find that internally strings are represented as lists of ascii code, e.g. L = "foo". will unify L with the list [102, 111, 111]
If you use write to display this, you'll get the list of ints out, whereas if you use put and do the characters one at a time you'll get the typically-desired text output. As such, we can write a quick set of rules to print the string (no error checking shown here)
writeAsStr([]) :- nl. % here we chose to end with a newline writeAsStr([H|T]) :- put(H), writeAsStr(T).
As an alternative, you can use name(Atom,String) to convert a string to an atom then write(Atom) to display it, e.g. to display "hi there" we could use
name(Atom,"hi there!"), write(Atom).
Unicode characters
Unicode characters can be displayed using their 8-digit (hex) code as follows:
Smiley = "\U0001F600", write_ln(Smiley). % displays a smiley emoticon