Trigger complete reload and recompile?

I’m using: SWI-Prolog version 8.1.9.

I have about 7 source files in my project. Throughout the project, there are conditional compilation blocks that all check a single predicate that is declared in one of source files. This predicate controls whether or not the portray statements I have created across the source files are compiled or not. So the predicate allows me to easily turn off all the portray statements when required for debugging.

I have noticed that when I change that predicate, then reconsult the source file that contains it, and then do a make, the other source files are not rebuilt. I know this because the portray statements in the other source files still behave as if that predicate that controls the compilation of the portray code is still in the old state.

When this happens, I exit SWI-Prolog completely and reload. Then everything is fine.

Is there a command I can use to tell SWI-Prolog to reload all the files in that are currently loaded and then completely rebuild them?

1 Like

I use this wrapper for portray/1 – it traps errors in my portray clauses and also provides a single place for turning off all my portray rules:

user:portray(Term) :-
    %% fail,  %% uncomment this line to turn off my_portray/1
    %% in the following, format/2 is used because
    %% print_message(warning, E) gives an infinite recursion.
    E = error(_, _),            % avoid trapping abort, timeout, etc.
    catch(my_portray(Term),
          E,
          format('EXCEPTION:portray(~q)', [Term])).
1 Like

An indirection is surely a good way of making the portray rules conditional. I’ve never felt much reason for conditional portray rules though. You add them to make your debug output more readable. If you have not enough detail and want to know the real term both the toplevel and tracer allow the temporary turn of using portray.

As for make, there is no checking of dependencies. It is rarely needed in well designed code. It is probably hard to accomplish without additional declarations. I’ve been thinking about that several times, but I still think it does more harm than good.

How do you do that? How do you turn them off temporarily?

Thanks Peter. I didn’t realize that simply failing the portray code would cause the debugger to just print it out in raw format. I guess I figured (wrongly) it would screw something up for the debugger.

Yes. Is there an equivalent in SWI-Prolog?

In the toplevel, use w to switch using portray off and p to turn it back on. In the (gui) tracer, double click the variable and in the resulting window you select how you want to show the term.

1 Like

No. It is easy to add as you can inspect the loaded files. I don’t think it is a good idea though. It still doesn’t guarantee you are in the same state as a plain load.

But if I had a command that reconsulted every loaded source file and then executed a make, why would I have to worry about the state? Wouldn’t everything be completely reloaded and rebuilt?

This is part of the design of print/1 and the ~p format escape: if a call to portray/1 fails, then fall back to the default write (this is implied by the documentation but not stated explicitly).

The design of portray (and write) is a bit problematic in that there’s no “context”, so if you want to do nice indentation, there’s no support. (A more general form of print_term/2` would be nice, but it’s way down on my “to-do” list.)

1 Like