Effefct of "write" option at the top-level

Apologies if this has been explained before. I had a quick look around and could not find anything on the Discourse.

It used to be that pressing w for “write” at the top-level during backtracking would print out a list in its entirety.

25 ?- l_systems:l_system(dragon_curve,l_systems,[f],6,O).
O = [f, +, g, +, f, -, g, +, f|…] [write]
O = [f, +, g, +, f, -, g, +, f|…] 
  Possible actions:
  ; (n,r,space,TAB): redo              | t:           trace&redo
  *:                 show choicepoint  | . (c,a,RET): stop
  w:                 write             | p:           print
  +:                 max_depth*5       | -:           max_depth//5
  b:                 break             | h (?):       help

Action? .

(This is with the latest daily build for windows (Mon Feb 23 05:17:53 2026) on a windows 11 machine.)

There’s a FAQ I could find on the SWI site, here:

This advises to press “+” at the top-level to increase the value of the max_depth/1 option for the answer_write_options flag.

I think this is new, or I missed it before because I always pressed “w” to see an entire list. In any case, what does the “write” option do now? Is there any way to get back its old functionality?

1 Like

“w” and “p” switch between write and print, notably (de)activating portray/1 hooks. “+” and “-” increase or decrease the depth. There is no immediate “give me all”. Why would you want that though? Typing a few times “+” should give more context than what you are prepared to read, while it avoids flooding the terminal with an unmanageable amount of data.

There is no real way “back” except changing the code or adding a portray/1 rule that (conditionally) prints the whole thing as you want. I’m happy to reconsider that if there is enough need/interest.

1 Like

Thanks. I often want to keep a record of a top-level session to a file with protocol/1 which I then can search for the output I’m looking for. In that case I want to see the entire output and I don’t care if it floods the screen, that’s more or less the point.

Part of my question is that I don’t understand what has changed. Clearly something has because in the past I could press “w” to see the entire output, without having to increase the context with “+”. I never had to add a portray/1 hook to do that, it was the standard behaviour of the top-level.

Can you explain what changed? How did the top-level interpret “w” before, and how has that changed now? Why did I see the entire context with “w” before but I don’t see it now? What is the difference between “write” and “print” at the top-level?

Edit: or just point me to the relevant documentation, of course.

Thanks!

Roughly, the commands (w/p/+/-) manage the Prolog flag answer_write_options and the answer is written using write_term/3 using these flags. So, you can get unbounded output by setting this flag appropriately (omit max_depth(N)). As you probably activate protocol/1 somewhere, you could set this flag at the same time. That seems a sensible solution to your problem.

The built-in management of this flag is in print_predicate/3 in boot/toplevel.pl.

What changed is how this Prolog flag is affected. w used to disable portrayed and max_depth and p enabled these. Now they merely toggle portrayed, while max_depth is modified with +/-. They are different features and combining these in one action is sometimes a bad choice. Also stepping max_depth rather than using 10 vs infinite seems useful.

1 Like

Thanks for clarifying. I agree that separating the effects of w and + is a better choice.

I usually start protocol/1 at the top-level, but I think I should be able to play around with the options of write_term/3 to get back the behaviour I’m used to.