Home > Archive > Prolog > March 2005 > how to do new line char
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to do new line char
|
|
|
|
Hi All:
I have a predicate which has the below as one of its clauses. So, the
output of my Prolog program is for example:
X = [s(aberdeen, 682, [penzance, exeter, bristol, birmingham,
manchester, carlisle, edinburgh, aberdeen]), s(aberystwyth, 352,
[penzance, exeter, bristol, swansea, aberystwyth]), s(birmingham, 274,
[penzance, exeter, bristol, birmingham]), s(brighton, 287, [penzance,
exeter, portsmouth, brighton]), s(bristol, 188, [penzance, exeter,
bristol]), ......
I would like to make the program print a newline character after each
s (small s) set that is displayed to improve readability of the
output. Note that each s has 3 parts to it. A destination city,
mileage, and then a list with other cities.
Here is the clause. I want to print a newline after each small
s--s(Vertex, Distance, Path) that is displayed. Is it possible? I'm
using SWI-Prolog.
S = s(Vertex, Distance, Path),
Thanks!
Drew
| |
| Brian Hulley 2005-03-02, 4:03 pm |
|
Drew wrote:
> Here is the clause. I want to print a newline after each small
> s--s(Vertex, Distance, Path) that is displayed. Is it possible? I'm
> using SWI-Prolog.
The built-in predicate (in most prologs including SWI-Prolog)
write_ln/1 takes a term as its argument and prints it out followed by a
new line. Therefore, instead of relying on the top level loop to print
out the result, you could instead compute the result and then pass this
result to a print predicate, which would recurse through the list
calling write_ln for each element. (There are several different output
predicates, you could try typing apropos(write) at the top level to
find out more about them).
ie go :- compute_graph(X), print_graph(X). etc
|
|
|
|
|