# Debug/3 only comments the first line?

**URL:** <https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603>\
**Category:** Help!\
**Tags:** discussion, how-to\
**Created:** [July 5, 2020, 3:36pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603 "2020-07-05T15:36:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [July 5, 2020, 3:36pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/1 "2020-07-05T15:36:48Z")

</div>

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).

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

```

vs.

```prolog
?- 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:

```prolog
?- 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)?

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 5, 2020, 4:06pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/2 "2020-07-05T16:06:10Z")

</div>

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](https://www.swi-prolog.org/pldoc/man?section=pldoc-comments) `/* ... */` 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](https://swi-prolog.discourse.group/t/adding-some-color-to-your-text-messages/2002)) so that color can be added.

Feel free to ignore all of this. 😀

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [July 5, 2020, 7:25pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/3 "2020-07-05T19:25:04Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 5, 2020, 7:26pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/4 "2020-07-05T19:26:53Z")

</div>

You should add those to the category [Nice to know](https://swi-prolog.discourse.group/c/nice-to-know/17) with a few working examples.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 5, 2020, 8:06pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/5 "2020-07-05T20:06:05Z")

</div>

After digging into this a bit more realized debug/3 in part of [Printing messages](https://www.swi-prolog.org/pldoc/man?section=printmsg).

Anne has a nice tutorial on this: [Printing Messages in SWI-Prolog](http://www.pathwayslms.com/swipltuts/message/index.html)

---

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [July 6, 2020, 1:26pm UTC](https://swi-prolog.discourse.group/t/debug-3-only-comments-the-first-line/2603/6 "2020-07-06T13:26:47Z")

</div>

Thanks. I will look more into this.

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