SWI-Prolog offers a query substitution mechanism similar to that of
Unix csh (csh(1)), called `history'. The availability of this feature is
controlled by set_prolog_flag/2,
using the history
prolog-flag. By default, history is
available if the prolog-flag readline
is
false
. To enable this feature, remembering the last 50
commands, put the following into your startup file (see section
2.2:
:- set_prolog_flag(history, 50). |
The history system allows the user to compose new queries from those typed before and remembered by the system. It also allows to correct queries and syntax errors. SWI-Prolog does not offer the Unix csh capabilities to include arguments. This is omitted as it is unclear how the first, second, etc. argument should be defined. (4)
The available history commands are shown in table 1.
!!. | Repeat last query |
!nr. | Repeat query numbered <nr> |
!str. | Repeat last query starting with <str> |
!?str. | Repeat last query holding <str> |
^old^new. | Substitute <old> into <new> in last query |
!nr^old^new. | Substitute in query numbered <nr> |
!str^old^new. | Substitute in query starting with <str> |
!?str^old^new. | Substitute in query holding <str> |
h. | Show history list |
!h. | Show this list |
Table 1 : History commands |
History expansion is executed after raw-reading. This is the first stage of read_term/2 and friends, reading the term into a string while deleting comment and canonising blank. This makes it hard to use it for correcting syntax errors. Command-line editing as provided using the GNU-readline library is more suitable for this. History expansion is first of all useful for executing or combining commands from long ago.