Loading and Editing Programs in Prolog
For loading programs in Prolog, the standard predicates are notations of bracket loader '[ …]', 'consult', 'reconsult'. For example,
The above goal opens the lists.pro file. It also helps to load the clause in lists.pro file into memory.
The Prolog program is deficient in two main ways. While loading the code, if there will be any syntax error, it shows that source code has a syntax error. While testing the program, if the programmer discovers any error, it shows that the program has a logical error. In Prolog, the program of the current version is usually considered the prototype for the correct version in the future. To edit the current version, retest, and reload it, this prototype gives us a common practice. The proper working of the rapid prototyping approach shows that the programmer has given a lot of time and effort to analyze the problem. The failure of the rapid prototyping approach shows that now we need to take up a pencil and paper, and we should rethink the requirements and start over.
In Prolog, we could call our editor using the following code and then upon returning from the editor.
To reload the program clause into the memory, one could use the following goal:
This will automatically replace the old definitions. Old clauses and new clauses have to remain in memory together if the user had used 'consult' rather than 'reconsult'. It actually depends upon the system of Prolog.
We will use 'reconsult', if more than one file has been loaded into the memory, and we need only one file to be reloaded. If the predicates are defined by the reload files and that predicates are not defined in the remaining file, the clauses that were originally loaded from the other files will not be disturbed by the reload.
The following example shows the bracket notation and it is very handy.
The above will load all three files into the memory of Prolog.
To edit the programs, many systems of Prolog depend upon the programmer that contains a favorite text editor. The following program in Prolog calls TextEdit on Mac.
Its source will be loaded to use this editor. Here, we will assume that it is local to the session of Prolog.
and then we will use the 'edit' goal. Now we will assume that file to edit is local to the session of Prolog.
Using the file loader, this TextEdit starts up. Edit the program, and using the same filename, save the program.
In the session of Prolog, we can reconsult the new version after editing and saving the programs in Prolog.
The user interactively supplies to load clauses using the goals.
The user then interactively type in the clause at the end of clauses using 'stop'. To end the input, we can use ^Z.