SWI-Prolog/swish

Printing out newlines.

Closed this issue · 2 comments

Hello everybody,

I'm using a swish query to try to print some text containing a newline.

X = 'hello\nworld', format(X).

fails with

Could not derive which predicate may be called from
	  format(A)

Screenshot:
Bildschirmfoto 2021-01-20 um 17 33 54

The only way that I've found to print something that contains a new line is
X = 'hello\nworld', format('~w', [X]).

Is this expected behavior or a bug?

Thanks!

Is this expected behavior or a bug?

This is expected. The sandbox must be able to figure out the format specifier as this can use ~@ to call arbitrary goals. format('hello\nworld') works fine, as does your solution.

A newline in e.g. write('hello\nworld'). would be nice, but is rather hard as the argument to write is a term that is rendered as a nested HTML <span> element to allow collapsing, etc. format/2 emits unstructured text, so we do not have that issue and can use a <pre> element.

Thank you!