________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
SPDX-FileCopyrightText: 2020 Paulo Moura <pmoura@logtalk.org>  
SPDX-FileCopyrightText: 2020 Michael T. Richter  
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________________________________________


% load the example:

?- logtalk_load(pengines(loader)).
...


% try the version that dumps the answers to the current output:

?- dumper::ask.
q(a)
q(b)
q(c)
true.


% try the version that allows collecting the answers:

?- engines::(ask(Engine), answers(Engine, Answers)).
Engine = 1,
Answers = [q(a), q(b), q(c)].


% retrieve answers on demand:

?- engines::ask(my_question).
true.

?- write('Doing something else ...').
Doing something else ...
true.

?- engines::answer(my_question, Answer).
Answer = q(a) .

?- write('Pause for tea ...').
Pause for tea ...
true.

?- engines::answer(my_question, Answer).
Answer = q(b) .

?- write('Any answers left?').
Any answers left?
true.

?- engines::answers(my_question, Answers).
Answers = [q(c)].


% use multiple engines concurrently:

?- engines::ask(E2).
E2 = 2.

?- engines::ask(E3).
E3 = 3.

?- engines::answer(2, A1).
A1 = q(a) .

?- engines::answer(3, A2).
A2 = q(a) .

?- engines::answer(2, A1).
A1 = q(b) ;
A1 = q(c) ;
false.

?- engines::answer(3, A2).
A2 = q(b) .

?- engines::answer(3, A2).
A2 = q(c) .

?- engines::answer(3, A2).
false.
