Did you know ... Search Documentation:
Predicate dcgshell/4
 dcgshell(+Interp, +Id, ?S1, ?S2) is semidet
 dcgshell(+Id, ?S1, ?S2) is semidet
 dcgshell(?S1, ?S2) is semidet
Runs an interactive shell where typed commands are interepreted as DCG phrases. The cumulative result of all these phrases takes the DCG state from S1 to S2. If present, Id is used to identify the shell and is written as part of the prompt. The default prompt is 'dcg'.

Pressing Ctrl-D at the prompt or typing 'halt' or 'end_of_file' terminates the shell unifying S2 with the final state. The command 'fail' terminates the shell and causes dcgshell/2 or dcgshell/3 as a whole to fail, without leaving any choice points.

dcgshell/4 allows the specification of an alternate interpreter other than call_dcg/3, which is the default in the other forms.

Special commands

module(M)
Switches context module of interpreter to M.
interp(I)
Change to a new interpreter. Eg, interp(time) will cause timing information to be printed after each command is interpreted.
X ^ Phrase
Causes Phrase to be interpreted after binding X to the id of the current interpreter. Since the id can be any term, you can use it as simple sort of environment in which you can keep data that might be useful later on.