Did you know ... | Search Documentation: |
Editing and incremental compilation |
One of the nice features of Prolog is that the code can be modified while the program is running. Using pure Prolog you can trace a program, find it is misbehaving, enter a break environment, modify the source code, reload it and finally do retry on the misbehaving predicate and try again. This sequence is not uncommon for long-running programs. For faster programs one will normally abort after understanding the misbehaviour, edit the source, reload it and try again.
One of the nice features of SWI-Prolog is the availability of make/0, a simple predicate that checks all loaded source files to see which ones you have modified. It then reloads these files, considering the module from which the file was loaded originally. This greatly simplifies the trace-edit-verify development cycle. For example, after the tracer reveals there is something wrong with prove/3 , you do:
?- edit(prove).
Now edit the source, possibly switching to other files and making
multiple changes. After finishing, invoke make/0,
either through the editor UI (Compile/Make (Control-C
Control-M
)) or on the top level, and watch the files being
reloaded.45Watching these files is
a good habit. If expected files are not reloaded you may have forgotten
to save them from the editor or you may have been editing the wrong file
(wrong directory).
?- make. % show compiled into photo_gallery 0.03 sec, 3,360 bytes