Debug/3 only comments the first line?

Just found out that debug/3 does not “comment” (or rather, “prepend with %”) not all lines it prints, only the first. I understand that one would generally only print one line (until one wants to print something more complex, that is, like a nicely formatted term).

?- debug(toplevel).
?- debug(toplevel,"This is monoline: ~q",[alpha]).
% This is monoline: alpha
true.

vs.

?- debug(toplevel).
?- debug(toplevel,"This is multiline: ~q\n~q\n~q",[alpha,bravo,charlie]).
% This is multiline: alpha
bravo
charlie
true.

One might expect:

?- debug(toplevel).
?- debug(toplevel,"This is multiline: ~q\n~q\n~q",[alpha,bravo,charlie]).
% This is multiline: alpha
% bravo
% charlie
true.

Probably an issue for the SWIPL bugzilla (is there one)?

IMHO the spirit of debug/3 is to print just one line of text.

However if a suggestion is to allow it to print multiple lines then instead of a % before each line it might be better to use the multi-line comment /* ... */ as that would make it faster to just wrap the text instead of spending the time to look for line endings. Perhaps an option could be added to state what kind of comments to use, single-line or multi-line.

Remember that the output from using debug/3 is not meant to create more Prolog code but just for review in trying to find a bug. To me the % just signifies to me it is a message from debug/3.

If we are also looking for suggestions for use with debug/3 then instead of basing it on format/3 it could be based on ansi_format/3 (ref) so that color can be added.

Feel free to ignore all of this. :grinning:

I have these in my arsenal, colour would be very welcome at times…

tick :- ansi_format([bold,fg(0,128,0)], '✔', []).
cross :- ansi_format([bold,fg(red)], '✘', []).
1 Like

You should add those to the category Nice to know with a few working examples.

After digging into this a bit more realized debug/3 in part of Printing messages.

Anne has a nice tutorial on this: Printing Messages in SWI-Prolog

Thanks. I will look more into this.

Prolog is quite a maze. Whenever you go down an avenue, there are sidequests that open up.

1 Like