Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request non-blocking sandbox, ev. needs yielding engine #10

Closed
Jean-Luc-Picard-2021 opened this issue Feb 8, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@Jean-Luc-Picard-2021
Copy link

Jean-Luc-Picard-2021 commented Feb 8, 2022

TauProlog has a new interfaces:

promiseQuery: queries a goal and returns a promise that is resolved
when the goal loads successfully, or rejected when there is an error. It
takes the same arguments as the query method.
http://tau-prolog.org/manual/promises-interface

The test case was a large limit and then:

longrunning :- 
    between(1,300,_),
    between(1,300,_),
    between(1,300,_),
    fail.
longrunning.

But I find that this sandbox here is blocking:

Unbenannt

http://tau-prolog.org/sandbox/

Is there another sandbox already online?

@Jean-Luc-Picard-2021 Jean-Luc-Picard-2021 changed the title Feb 8, 2022
@ghost ghost assigned jariazavalverde Feb 8, 2022
@jariazavalverde
Copy link
Contributor

Tau Prolog is non-blocking, but as a National Department of Traffic slogan said: we can't drive for you. To release the browser you have two options: call an asynchronous predicate (such as sleep/1) that sleeps execution for a while, or use the inference limit that you can set in Tau Prolog.

For instance, the following code doesn't freeze the browser:

:- use_module(library(os)).

p :-
    sleep(0),
    write(p), nl,
    p.

Tau Prolog allows you to create a sandbox that sleeps every x inferences, but it doesn't by default because that delays execution.

@jariazavalverde
Copy link
Contributor

The Tau Prolog sandbox is just that, a sandbox, and it allows you to set an inference limit to prevent the browser from freezing. It is built using the 3 main methods of Tau Prolog: consult, query and answer.

http://tau-prolog.org/manual/a-simple-tutorial

You can set up a sandbox that runs a query with a limit of, say, 1000 inferences. If the limit of inferences is reached, in the callback of the answer method, you can make it continue looking for the answer. That way the interpreter can stop working automatically from time to time, so that the browser takes care of the rest of the events.

In our current sandbox, when the query stops the user has to explicitly request that the search continue, requesting another answer. But this behavior can be changed by modifying the callback.

imagen

Regarding sleep/1 predicate, every time you stop the execution so that the browser processes the rest of the events, whatever way it is, there may be a delay. Precisely because you stop for other events to be processed. JavaScript is single-thread, and this is just a negative effect of its concurrency model. In any case, both with sleep/1 predicate or with the inference limit, the user can choose how often to stop the execution.

@jariazavalverde jariazavalverde transferred this issue from tau-prolog/tau-prolog Feb 8, 2022
@jariazavalverde
Copy link
Contributor

Added. You only have to uncheck the stop option (the limit of inferences is still necessary).

imagen

You can check the option while running to stop the execution in the next limit of inferences.

@jariazavalverde jariazavalverde added the enhancement New feature or request label Feb 8, 2022
@Jean-Luc-Picard-2021
Copy link
Author

Ok, interesting, you can als cancel, by checking stop again.
But what is a good limit value? The default 10000 seems a
little too high, the GUI feels jiggy.

@jariazavalverde
Copy link
Contributor

It depends on the browser and the program. Something like 1000 should be fine, but it's a matter of testing I guess. (Note that you have to reconsult after setting the limit).

@Jean-Luc-Picard-2021
Copy link
Author

Strange I have hit some browser incompatibility, on MacOSX.

The new feature works in Seamonkey:

Bildschirmfoto 2022-02-09 um 00 18 54

It does not work in Chrome:

Bildschirmfoto 2022-02-09 um 00 18 08

@jariazavalverde
Copy link
Contributor

It does not work in Chrome:

That is probably due to the browser cache. Refresh with Cntrl+F5 or clear the cache.

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Feb 9, 2022

Will check the browser later again.

I always admire Steve Jobs, how he introduced the MacIntosh
with a mouse that only had one button. Those times there were
mouses with 3 buttons.

So currently trying to figure out what a good GUI would be.
I cannot speak for Tau Prolog. But in my system Limit is a
system resource, that the end-user has nothing

to do with. It is planned that for non-blocking via some
auto-tuning the optimal value is found. Browsers have
a certain affinity to 60 frames per second.(*)

Not yet sure how this turns out. For the control buttons,
I am rather think of something else. Don't know yet what.
Was just having a look at SWISH, it shows me an animation

and an abort button:

Bildschirmfoto 2022-02-09 um 01 06 45

after a while it shows stats:

Bildschirmfoto 2022-02-09 um 01 08 03

the abort button shows again after redo:

Bildschirmfoto 2022-02-09 um 01 09 23

(*)
I found some docu about that. A browser might also updrade
or downgrade the frequency. There is also something related
to animation, called requestAnimationFrame(), but this is

probably not needed for DOM updates.

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Feb 9, 2022

You can check here, but a monitor might have more Hz:

https://www.testufo.com/animation-time-graph
Bildschirmfoto 2022-02-09 um 01 25 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants