query_hook/6
hook:- multifile query_hook/6.
query_hook(
+QueryClass,
+Prompt,
+PromptLines,
+Help,
+HelpLines,
-Answer)
Provides a method of overriding Prolog's default keyboard based input requests. The query hook is used by the Quintus User Interface.
yes_or_no(
Question)
yes
or no
.
toplevel
yes
or no
yes_no_proceed
yes
, no
, or proceed
.
This provides a way of overriding Prolog's default method of interaction. If this predicate fails, Prolog's default method of interaction is invoked.
The default method first prints out the prompt, then if the response from the user is not one of the allowed values, the help message is printed.
It is useful to compare this predicate to message_hook/3
, since
this explains how you might use the Prompt, PromptLines,
Help, HelpLines.
An exception raised by this predicate causes an error message to be printed and then the default method of interation is invoked. In other words, exceptions are treated as failures.
If Prolog is looking for a yes-no response to one
question Done?
, as in the toplevel, this request for input can be captured
query_hook(toplevel,_,_,_,_,Answer):- my_yes_no('Done?',Answer).
where my_yes_no/2
binds Answer to either yes
or no
.
Here is roughly how the default method works. Notice the
interaction with query_abbreviation/3
.
query_hook(QueryClass,_,PromptLines,_,HelpLines,Answer):- 'QU_messages':query_abbreviation(QueryClass, AbbreviationPrompt, Pairs), repeat, ( print_message_lines(user_output,'',PromptLines), ( AbbreviationPrompt == '' -> write(Stream,' ') ; format(Stream,' ~w ',[AbbreviationPrompt]) ), flush_output(Stream), get0(C), member(Answer-Abrv,Pairs), member(C,Abrv), ! ; print_message_lines(Stream,'',HelpLines), fail ).
query_abbreviation/3
,
message_hook/3
,
print_message_lines/3
ref-msg