?- consult('lists.pro').opens the file lists.pro and loads the clauses in that file into memory. If this program was not correct, and one edited the file using the goal
?- edit('lists.pro').then upon returning from the editor (and assuming that the new version of the file was resaved using the same file name), one could use the goal
? reconsult('lists.pro').to reload the program clauses into memory, automatically replacing the old definitions. If one had here used 'consult' rather than 'reconsult' the old (and possibly incorrect) clauses would have remained in memory along with the new clauses (depends upon the Prolog system, actually).
If several files have been loaded into memory, and one needs to be reloaded, use 'reconsult'. If the reloaded file defines predicates which are not defined in the remaining files then the reload will not disturb the clauses that were originally loaded from the other files.
The bracket notation is handy. For example,
?- ['file1.pro',file2.pro',file3.pro'].
would load (effectively reconsult) all three files into memory.
Most Prolog interpreter systems have a built-in editor, or allow interactive access to other editors. To call the EDT editor on the VAX/VMS system, one can use the follow program, in file edit.pro.
To use this editor, its source must be loaded::- use_module(library(strings)). edit(File) :- concat_atom(['edt ', File],Cmd), /* e.g., use edt as editor */ vms(dcl(Cmd)), write('Reconsult '), write(File), write(' (y or n)? '), read(R), (R == y ; R == yes), reconsult(File).
?- ['edit.pro'].and then an 'edit' goal can be used:
yes
?- edit('lists.pro').For SWI Prolog on the Sun Workstations, it is perhaps easiest to use the emacs editor or the Solaris text editor tool to edit programs. For the Solaris text editor tool, edit the Prolog program in a separate text editor window and save the program when the desired changes have been made; then reconsult the edited program as above. The emacs editor is capable of executing the Prolog goals for the edited program from the editor environment. See the emacs documentation to learn how to use this program editor environment.
{ EDT editor starts up. Edit the program... Exit the editor ...}
Reconsult lists.pro (y or n)? y.
{ Prolog reconsults the file lists.pro, replacing old definitions with the new, edited ones.}
To load clauses supplied interactively by the user, use the goals ?-consult(user), ?- reconsult(user), or ?-[user]. The user then types in clauses interactively, using stop '.' at the end of clauses, and ^Z to end input.