Now I got an idea how to asyncify the ISO core standard I/O.
The idea is very simple and I try to solve one problem: How
can we make for example get_code/2 asyncified, without
sacrificing performance? I came up with this sketch:
get_code(S, C) :- get_code_buffered(S, C), !.
get_code(S, C) :- async_read_buffer(S), get_code(S, C).
There are some unresolved issues in the above code, like
how return end of file, i.e. -1 or how to deal with surrogate pairs.
But essentially the idea is that the stream S has a buffer
somewhere and that the fast path is to read from this buffer,
and we only need to yield when we replenish the buffer via
some I/O. This could give a quite fast asyncified get_code/2.
Is there any Prolog system that did already something like this?
I always see that get_code/2 is a primitive and was also folllowing
this approach in my systems so far. In the above I bootstrap it from two
other primitives, a synchronous one and a asynchronous one,
make it itself not anymore primitive. get_code_buffered/2 would
fail if it has reached the end of the buffer.
But there is a lot of work to do, peek_code/2 needs a similar
treatment, and then in my system I have also get_atom/3, which
would need some treatment. Scryer Prolog would go for the
XXX_char predicates first, if they are present in a Prolog system
they would also need some treatment. Also the Python and the
JavaScript target might turn out different. In JavaScript there are
different fetch modes, chunked and non-chunked. In non-chunked
we might get the whole file in one go, a second call to async_read_buffer/1 would not exist. Chunked is related to what SWI-Prolog calls http
streaming. I don’t know the details yet. And then maybe it should transparently choose something synchronous if asynchronous
behaviour is not demanded from the Prolog interpreter at all.
Mostowski Collapse schrieb am Mittwoch, 10. August 2022 um 09:28:41 UTC+2:
Now I got an idea how to asyncify the ISO core standard I/O.
The idea is very simple and I try to solve one problem: How
can we make for example get_code/2 asyncified, without
sacrificing performance? I came up with this sketch:
get_code(S, C) :- get_code_buffered(S, C), !.
get_code(S, C) :- async_read_buffer(S), get_code(S, C).
There are some unresolved issues in the above code, like
how return end of file, i.e. -1 or how to deal with surrogate pairs.
But essentially the idea is that the stream S has a buffer
somewhere and that the fast path is to read from this buffer,
and we only need to yield when we replenish the buffer via
some I/O. This could give a quite fast asyncified get_code/2.
Is there any Prolog system that did already something like this?
I always see that get_code/2 is a primitive and was also folllowing
this approach in my systems so far. In the above I bootstrap it from two
other primitives, a synchronous one and a asynchronous one,
make it itself not anymore primitive. get_code_buffered/2 would
fail if it has reached the end of the buffer.
'When a clown moves into a palace, he doesn't
become a king. The palace becomes a circus.'
-Turkish proverb
Now we have two ClownPrologs:
ClownProlog Nr. 1: Ciao Prolog:
This here looks like a Prolog terminal in the browser,
but doesn't behave like a Prolog terminal:
https://ciao-lang.org/playground/
Try read/1 etc.. Its documented that this is a limitation.
ClownProlog Nr. 2: SWI-Prolog:
Maybe inspired by Ciao Prolog playground, that they made
quickly a rip off? Its a little better off, one can abort a query. https://dev.swi-prolog.org/wasm/shell
But try read/1 etc..
My proposal for async ISO core standard I/O could
adress this problem. But interestingly its also not top
priority for Dogelog. I just figured out that I need other
stuff first. But Dogelog does not try to present the illusion
of a terminal, when it does not yet have a terminal. None
of the examples try to provide such a illusion.
Since priorities are different, it will clearly take weeks
or months, for a demonstration. Also there are not
much shoulders to climb, at least I didn't find
a lot of precedents, and who wants to climb giant
morons? ClownProlog Nr. 2 is even not asyncified, they
even don't know what this is. ClownProlog Nr. 1 could
be better off, they seem to have a haze idea.
LoL
Mostowski Collapse schrieb am Donnerstag, 11. August 2022 um 14:41:20 UTC+2:
'When a clown moves into a palace, he doesn't
become a king. The palace becomes a circus.'
-Turkish proverb
Now we have two ClownPrologs:
ClownProlog Nr. 1: Ciao Prolog:
This here looks like a Prolog terminal in the browser,
but doesn't behave like a Prolog terminal: https://ciao-lang.org/playground/
Try read/1 etc.. Its documented that this is a limitation.
ClownProlog Nr. 2: SWI-Prolog:
Maybe inspired by Ciao Prolog playground, that they made
quickly a rip off? Its a little better off, one can abort a query. https://dev.swi-prolog.org/wasm/shell
But try read/1 etc..
My proposal for async ISO core standard I/O could
adress this problem. But interestingly its also not top
priority for Dogelog. I just figured out that I need other
stuff first. But Dogelog does not try to present the illusion
of a terminal, when it does not yet have a terminal. None
of the examples try to provide such a illusion.
Why could be ClownProlog Nr. 1 better of.
They have an async facade, at least their file
says so ciao-async.js. Thats already a good
start, although it has the unholy combination
with a worker. ClownProlog Nr. 2 demonstrates
a solution without a worker. For ClownProlog Nr. 1
I am refering to this here:
Monaco Playground for Ciao Prolog
Madrid, Junio 2022 - Guillermo Garcia Pradales https://oa.upm.es/71073/1/TFG_GUILLERMO_GARCIA_PRADALES.pdf
Pitty they are so closed. The tutorial application
mentioned in the PDF is nowhere seen. They are
similarly close like when they published this here:
Lightweight compilation of (C)LP to JavaScript https://arxiv.org/pdf/1210.2864.pdf
It never made it into any Ciao distribution. Which is
anyway now obsolete, since Ciao WASM is faster
than Ciao JS. Ciao WASM is really brilliant!
Mostowski Collapse schrieb am Donnerstag, 11. August 2022 um 14:52:58 UTC+2:
Since priorities are different, it will clearly take weeks
or months, for a demonstration. Also there are not
much shoulders to climb, at least I didn't find
a lot of precedents, and who wants to climb giant
morons? ClownProlog Nr. 2 is even not asyncified, they
even don't know what this is. ClownProlog Nr. 1 could
be better off, they seem to have a haze idea.
LoL
Mostowski Collapse schrieb am Donnerstag, 11. August 2022 um 14:41:20 UTC+2:
'When a clown moves into a palace, he doesn't
become a king. The palace becomes a circus.'
-Turkish proverb
Now we have two ClownPrologs:
ClownProlog Nr. 1: Ciao Prolog:
This here looks like a Prolog terminal in the browser,
but doesn't behave like a Prolog terminal: https://ciao-lang.org/playground/
Try read/1 etc.. Its documented that this is a limitation.
ClownProlog Nr. 2: SWI-Prolog:
Maybe inspired by Ciao Prolog playground, that they made
quickly a rip off? Its a little better off, one can abort a query. https://dev.swi-prolog.org/wasm/shell
But try read/1 etc..
My proposal for async ISO core standard I/O could
adress this problem. But interestingly its also not top
priority for Dogelog. I just figured out that I need other
stuff first. But Dogelog does not try to present the illusion
of a terminal, when it does not yet have a terminal. None
of the examples try to provide such a illusion.
LoL, I guess somebody didn't update their servers:
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
https://www.prolog.logtalk.org/ is producing nonsense now.
Mostowski Collapse schrieb am Freitag, 12. August 2022 um 15:49:54 UTC+2:
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
Mostlikely there will never be a Lists PEP, since the
Prolog systems are much to much ossified. A little chance
might have some newcomers, like for example:
- Tau Prolog
- Scryer Prolog
- Trealla Prolog
- Dogelog Player
- Ichiban Prolog
- What else?
But the old whales have possibly no chance to do something,
would require too much refactoring. Because most likely lists and
friends are used internally by the compiler and runtime.
What would have a chance maybe, if there were forks especially
for some playgrounds. Lets say such a fork were Ciao2. Then
there would be maybe a chance if we would see:
- Ciao2 Prolog
- GNU2 Prolog
- SICStus2 Prolog
- What else?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 10:48:20 UTC+2:
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
Ulrich Neumerkel was invesitigating certain predicates in
the past. Like for example here. This seems be a kind of
updated, I see Ichiban Prolog column, must be newer:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length
If you append .html,v, you see the versions of this file:
1.23
date 2022.07.16.13.24.22
Whether somebody can jump into this role of Ulrich Neumerkel,
especially from academia, I doubt. They don’t have time
for that. They have other jobs to do. Maybe a better
automatization would help. I wrote a new version of a test
runner for Dogelog player. There are various test runners
included in various Prolog systems. Even Logtalk has
a test runner. For a continous integration / continous
deployment pipeline, that would do a kind of PEP assesment
across Prolog systems, that is visible together with the PEP,
somesuch could be a useful tool.
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:38:29 UTC+2:
If I only pick substract/3 its already here:
- YAP Prolog
- ECLiPSe Prolog
- What else?
I cannot asses the YAP Prolog systems so easily. For example,
there is maybe a pretty printing problem. I see strange stuff
like this extra memberchk/0 and extra subtract/0:
subtract([], _, []) :- subtract.
subtract([E|T], D, R) :-
memberchk(E, D), memberchk,
subtract(T, D, R).
subtract([H|T], D, [H|R]) :-
subtract(T, D, R). https://www.dcc.fc.up.pt/~vsc/yap/lists_8yap_source.html
Some broken pretty printer?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:37:35 UTC+2:
Mostlikely there will never be a Lists PEP, since the
Prolog systems are much to much ossified. A little chance
might have some newcomers, like for example:
- Tau Prolog
- Scryer Prolog
- Trealla Prolog
- Dogelog Player
- Ichiban Prolog
- What else?
But the old whales have possibly no chance to do something,
would require too much refactoring. Because most likely lists and friends are used internally by the compiler and runtime.
What would have a chance maybe, if there were forks especially
for some playgrounds. Lets say such a fork were Ciao2. Then
there would be maybe a chance if we would see:
- Ciao2 Prolog
- GNU2 Prolog
- SICStus2 Prolog
- What else?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 10:48:20 UTC+2:
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
If I only pick substract/3 its already here:
- YAP Prolog
- ECLiPSe Prolog
- What else?
I cannot asses the YAP Prolog systems so easily. For example,
there is maybe a pretty printing problem. I see strange stuff
like this extra memberchk/0 and extra subtract/0:
subtract([], _, []) :- subtract.
subtract([E|T], D, R) :-
memberchk(E, D), memberchk,
subtract(T, D, R).
subtract([H|T], D, [H|R]) :-
subtract(T, D, R).
https://www.dcc.fc.up.pt/~vsc/yap/lists_8yap_source.html
Some broken pretty printer?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:37:35 UTC+2:
Mostlikely there will never be a Lists PEP, since the
Prolog systems are much to much ossified. A little chance
might have some newcomers, like for example:
- Tau Prolog
- Scryer Prolog
- Trealla Prolog
- Dogelog Player
- Ichiban Prolog
- What else?
But the old whales have possibly no chance to do something,
would require too much refactoring. Because most likely lists and
friends are used internally by the compiler and runtime.
What would have a chance maybe, if there were forks especially
for some playgrounds. Lets say such a fork were Ciao2. Then
there would be maybe a chance if we would see:
- Ciao2 Prolog
- GNU2 Prolog
- SICStus2 Prolog
- What else?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 10:48:20 UTC+2:
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
In length/2 its easy to nevertheless support these errors,
since one can use a var/1 test in the second argument instead
of a ground/1 test in the first argument, when deciding the mode.
In as far I can offer this behaviour:
?- length([a,b,c],x).
error(type_error(integer, x), [user:1])
?- length([a,b,c],-1).
fail.
?- length(X,-1).
fail.
Isn’t the fail nice?
The fail is not on the agenda of Ulrich Neumerkel.
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:47:39 UTC+2:
Unfortunately the test campaigns of Ulrich Neumerkel
don't have much merit. On the other hand he recently
raised a ticket about:
?- setof(t,(L=2;L=1),L).
uncaught exception: error(type_error(list,1),sort/2), unexpected.
slightly implying he wants not a type error? On the other
hand his latest length/2 test cases, are like 75% type
error and domain error tests of some output argument,
which in my opinion can be easily dropped from a certain
interpretation of the ISO core standard. It only causes
slowdown of the Prolog system. Among the Prolog systems
that pass these nonsense tests are also mostly Prolog
systems that are not the fastest. See for yourself:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:39:40 UTC+2:
Ulrich Neumerkel was invesitigating certain predicates in
the past. Like for example here. This seems be a kind of
updated, I see Ichiban Prolog column, must be newer:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length
If you append .html,v, you see the versions of this file:
1.23
date 2022.07.16.13.24.22
Whether somebody can jump into this role of Ulrich Neumerkel,
especially from academia, I doubt. They don’t have time
for that. They have other jobs to do. Maybe a better
automatization would help. I wrote a new version of a test
runner for Dogelog player. There are various test runners
included in various Prolog systems. Even Logtalk has
a test runner. For a continous integration / continous
deployment pipeline, that would do a kind of PEP assesment
across Prolog systems, that is visible together with the PEP,
somesuch could be a useful tool.
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:38:29 UTC+2:
If I only pick substract/3 its already here:
- YAP Prolog
- ECLiPSe Prolog
- What else?
I cannot asses the YAP Prolog systems so easily. For example,
there is maybe a pretty printing problem. I see strange stuff
like this extra memberchk/0 and extra subtract/0:
subtract([], _, []) :- subtract.
subtract([E|T], D, R) :-
memberchk(E, D), memberchk,
subtract(T, D, R).
subtract([H|T], D, [H|R]) :-
subtract(T, D, R). https://www.dcc.fc.up.pt/~vsc/yap/lists_8yap_source.html
Some broken pretty printer?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:37:35 UTC+2:
Mostlikely there will never be a Lists PEP, since the
Prolog systems are much to much ossified. A little chance
might have some newcomers, like for example:
- Tau Prolog
- Scryer Prolog
- Trealla Prolog
- Dogelog Player
- Ichiban Prolog
- What else?
But the old whales have possibly no chance to do something,
would require too much refactoring. Because most likely lists and friends are used internally by the compiler and runtime.
What would have a chance maybe, if there were forks especially
for some playgrounds. Lets say such a fork were Ciao2. Then
there would be maybe a chance if we would see:
- Ciao2 Prolog
- GNU2 Prolog
- SICStus2 Prolog
- What else?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 10:48:20 UTC+2:
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
Unfortunately the test campaigns of Ulrich Neumerkel
don't have much merit. On the other hand he recently
raised a ticket about:
?- setof(t,(L=2;L=1),L).
uncaught exception: error(type_error(list,1),sort/2), unexpected.
slightly implying he wants not a type error? On the other
hand his latest length/2 test cases, are like 75% type
error and domain error tests of some output argument,
which in my opinion can be easily dropped from a certain
interpretation of the ISO core standard. It only causes
slowdown of the Prolog system. Among the Prolog systems
that pass these nonsense tests are also mostly Prolog
systems that are not the fastest. See for yourself:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:39:40 UTC+2:
Ulrich Neumerkel was invesitigating certain predicates in
the past. Like for example here. This seems be a kind of
updated, I see Ichiban Prolog column, must be newer:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/length
If you append .html,v, you see the versions of this file:
1.23
date 2022.07.16.13.24.22
Whether somebody can jump into this role of Ulrich Neumerkel,
especially from academia, I doubt. They don’t have time
for that. They have other jobs to do. Maybe a better
automatization would help. I wrote a new version of a test
runner for Dogelog player. There are various test runners
included in various Prolog systems. Even Logtalk has
a test runner. For a continous integration / continous
deployment pipeline, that would do a kind of PEP assesment
across Prolog systems, that is visible together with the PEP,
somesuch could be a useful tool.
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:38:29 UTC+2:
If I only pick substract/3 its already here:
- YAP Prolog
- ECLiPSe Prolog
- What else?
I cannot asses the YAP Prolog systems so easily. For example,
there is maybe a pretty printing problem. I see strange stuff
like this extra memberchk/0 and extra subtract/0:
subtract([], _, []) :- subtract.
subtract([E|T], D, R) :-
memberchk(E, D), memberchk,
subtract(T, D, R).
subtract([H|T], D, [H|R]) :-
subtract(T, D, R). https://www.dcc.fc.up.pt/~vsc/yap/lists_8yap_source.html
Some broken pretty printer?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 16:37:35 UTC+2:
Mostlikely there will never be a Lists PEP, since the
Prolog systems are much to much ossified. A little chance
might have some newcomers, like for example:
- Tau Prolog
- Scryer Prolog
- Trealla Prolog
- Dogelog Player
- Ichiban Prolog
- What else?
But the old whales have possibly no chance to do something,
would require too much refactoring. Because most likely lists and friends are used internally by the compiler and runtime.
What would have a chance maybe, if there were forks especially
for some playgrounds. Lets say such a fork were Ciao2. Then
there would be maybe a chance if we would see:
- Ciao2 Prolog
- GNU2 Prolog
- SICStus2 Prolog
- What else?
Mostowski Collapse schrieb am Sonntag, 14. August 2022 um 10:48:20 UTC+2:
Woa! Maybe make it priority a library(lists) standard?
- Lists
Poor LogNonsenseTalk had to implement everything on
its own. Doesn't this lead to some code bloat? If you have
a playground and WASM, you probably don't want this,
everything twice going over the wire: https://github.com/LogtalkDotOrg/logtalk3/blob/master/library/types/list.lgt
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Maybe a good start for Cooperative Multitasking would
be an engine API? Or a delimited continuation API?
Delimited continuation is sometimes favored to make
stare transformers. Here is a little benchmark from SWI-Prolog:
/* shift/1, warm run */
?- time(run_state(fib(28), 0, S)).
% 9,770,334 inferences, 2.437 CPU in 2.861 seconds (85% CPU, 4008342 Lips)
S = 514229 .
/* engine_yield/1, warm run */
?- time(run_state(fib(28), 0, S)).
% 3,599,612 inferences, 1.109 CPU in 1.177 seconds (94% CPU, 3244721 Lips)
S = 514229 .
Woa! engine_yield/1 was more than twice as fast as shift/1! Was using this fibonacci with spurious choice points, as often found in pure DCG:
fib(0) :- inc(1).
fib(1) :- inc(1).
fib(N) :- N > 1, M is N-1, fib(M), J is M-1, fib(J).
Mostowski Collapse schrieb am Freitag, 12. August 2022 um 15:49:54 UTC+2:
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Quite an amazing test case:
/* SWI-Prolog 8.5.14 */
?- time(run_state(fib(25), 0, S)).
% 2,306,455 inferences, 0.453 CPU in 0.499 seconds
(91% CPU, 5090108 Lips)
S = 121393 .
/* Scryer Prolog 0.9.0 */
?- time(run_state(fib(25), 0, S)).
% CPU time: 12.532s
S = 121393
Maybe an interesting experiment would be, whether SLG Tabling
can be implemented with engine_yield/1 instead of shift/1?
Mostowski Collapse schrieb am Samstag, 20. August 2022 um 13:41:56 UTC+2:
Maybe a good start for Cooperative Multitasking would
be an engine API? Or a delimited continuation API?
Delimited continuation is sometimes favored to make
stare transformers. Here is a little benchmark from SWI-Prolog:
/* shift/1, warm run */
?- time(run_state(fib(28), 0, S)).
% 9,770,334 inferences, 2.437 CPU in 2.861 seconds (85% CPU, 4008342 Lips) S = 514229 .
/* engine_yield/1, warm run */
?- time(run_state(fib(28), 0, S)).
% 3,599,612 inferences, 1.109 CPU in 1.177 seconds (94% CPU, 3244721 Lips) S = 514229 .
Woa! engine_yield/1 was more than twice as fast as shift/1! Was using this fibonacci with spurious choice points, as often found in pure DCG:
fib(0) :- inc(1).
fib(1) :- inc(1).
fib(N) :- N > 1, M is N-1, fib(M), J is M-1, fib(J).
Mostowski Collapse schrieb am Freitag, 12. August 2022 um 15:49:54 UTC+2:
Anyway why ask for permission to write enhancement
proposals (EPs), just write them? From the time of Paulo
Moura there are the most EPs. Prolog threads/messages
(October 28, 2008), Prolog global variables, what else? You
see the focus of his endeavours here, everything stalled
in the below forum in 2009, where did it go?
- Core Revision
- Definite Clause Grammars
- Globals and Arrays
- Multi-Threading
- Portable Operating-System Interface
- Unicode
https://www.prolog.logtalk.org/
What PEPs do you want to write? Did his focus match the
requirements of Web Prolog. I do see missing:
- Cooperative Multitasking
- Foreign Functions Calls
- Format and Protocolls
- Prolog Corouting & Attributed Variables
- What else?
Cooperative Multitasking would cover issues that recently
poped up in the WASM and non-WASM integration of
Prolog system into a HTML page, similarly Foreign Functions
Calls, like having a DOM event handler call Prolog, or manipulating
DOM by Prolog. The Format and Protocolls item can mean HTTP,
JSON, etc… The first 3 topics are somehow interconnected, so if you
botch one of the 3 topics, the overall result is not so good.
Its both with shift/1 !
Mostowski Collapse schrieb am Samstag, 20. August 2022 um 20:22:38 UTC+2:
Quite an amazing test case:
/* SWI-Prolog 8.5.14 */
?- time(run_state(fib(25), 0, S)).
% 2,306,455 inferences, 0.453 CPU in 0.499 seconds
(91% CPU, 5090108 Lips)
S = 121393 .
/* Scryer Prolog 0.9.0 */
?- time(run_state(fib(25), 0, S)).
% CPU time: 12.532s
S = 121393
Pitty the CW631 paper here: https://www.cs.kuleuven.be/publicaties/rapporten/cw/CW631.pdf
doesn’t show Felleisen prompt/control implemented with difference lists:
/* Vanilla conjunction list solve/1 extended to control/3 */
control([], none, []).
control([prompt(A)|B], A, B).
control([control(L, P, Q)|B], X, Y) :- control(L, P, Q), control(B, X, Y). control([A|B], X, Y) :- rule(A,C,B), control(C, X, Y).
/* Difference List variant of clause/2 */ rule(sum(A+B),[prompt(ask(A)),prompt(ask(B))|R],R). rule(with_list(G,P,Q),[control(G,T,C),with_list2(T,C,P,Q)|R],R). rule(with_list2(none,_,P,P),R,R). rule(with_list2(ask(X),C,[X|P],Q),[with_list(C,P,Q)|R],R).
Works fine:
?- control([with_list([sum(S)],[1,2,3],L)],_,_).
S = 1+2,
L = [3] .
Thats just your humanly ape brain acceptance curve:
- Resistance
- Denial
- Exploration
- Commitment
Mostowski Collapse schrieb am Donnerstag, 11. August 2022 um 17:27:36 UTC+2:
Thats just your humanly ape brain acceptance curve:If you are a slow thinker, you pass these quadrants slowly,
- Resistance
- Denial
- Exploration
- Commitment
maybe you never reach the end. Here is an example of a
slow thinker, Ulrich Neumerkel, concerning Unicode:
bla bla bla TPTP and bla bla bla WG21/N3146 https://www.tptp.org/TPTP/SyntaxBNF.html#lower_alpha https://github.com/mthom/scryer-prolog/issues/1515#issuecomment-1225242783 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3146.html
LoL
Slow thinking can lead to constant pain. Like here:
And, indeed, in the case of an atom the escaping is not necessary:
?- write('foo"bar').
foo"bar true. https://github.com/mthom/scryer-prolog/issues/1552#issuecomment-1207677642
What does "not necessary" mean. Thats nonsense.
Wouldn't it be a better and less confusing explanation that write/1
must behave as putatom/1, and everything else would be a bug,
since it has quoted(false)?
At least this is what the ISO core standard tells me:
- ISO/IEC 13211-1:1995(E), Page 100
So basically write/1 will behave, concerning atoms
as if (in DEC-10 Dialect):
[...]
write(X) :- atom(X), name(X,L), putlist(L).
[...]
putlist([X|Y]) :- put(X), putlist(Y).
putlist([]).
If you would like to be TPTP compatible (versus v8.1.0.0),
you would need to ban this:
$ target/release/scryer-prolog -v
"v0.9.0-181-g8e9302ea"
$ target/release/scryer-prolog
?- X = hörgerät.
X = hörgerät.
So Scryer Prolog is now somewhere between TPTP
and a Prolog Unicode, neither fish nor fowl,
I cannot parse this, doesn't work in Scryer Prolog:
$ cat text.pl
text("«The Logos of Cybele is the idea that the Great Mother creates\n\
and kills everything. It is not eternity (Apollo) or the circle\n\ (Dionysus), but something that acts in her way with blind\n\
and absolute power. A form of progress: bottom-up growth.\n\
We are experiencing the final attack of Cybele, of the Great Risen\n\ Mother, with feminism, artificial intelligence, globalization,\n\
democracy, liberalism, and so on»").
I get this error:
$ target/release/scryer-prolog
?- ['text.pl'].
error(syntax_error(missing_quote),read_term/3:0).
false.
Works fine in SWI-Prolog:
?- text(X), write(X), nl, fail; true.
«The Logos of Cybele is the idea that the Great Mother creates
and kills everything. It is not eternity (Apollo) or the circle
(Dionysus), but something that acts in her way with blind
and absolute power. A form of progress: bottom-up growth.
We are experiencing the final attack of Cybele, of the Great Risen
Mother, with feminism, artificial intelligence, globalization,
democracy, liberalism, and so on»
true.
Mostowski Collapse schrieb am Mittwoch, 24. August 2022 um 15:08:40 UTC+2:
Mostowski Collapse schrieb am Donnerstag, 11. August 2022 um 17:27:36 UTC+2:
Thats just your humanly ape brain acceptance curve:If you are a slow thinker, you pass these quadrants slowly,
- Resistance
- Denial
- Exploration
- Commitment
maybe you never reach the end. Here is an example of a
slow thinker, Ulrich Neumerkel, concerning Unicode:
bla bla bla TPTP and bla bla bla WG21/N3146 https://www.tptp.org/TPTP/SyntaxBNF.html#lower_alpha https://github.com/mthom/scryer-prolog/issues/1515#issuecomment-1225242783 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3146.html
LoL
Holy Cow, Logtalk is the converse of Ciao Prolog.
Its kind of the inverted image of the library(lists)
of Ciao Prolog. What Logtalk has:
subtract([], _, []).
subtract([Head| Tail], List, Rest) :-
( memberchk(Head, List) ->
subtract(Tail, List, Rest)
; Rest = [Head| Tail2],
subtract(Tail, List, Tail2)
).
is not in Ciao Prolog. And vice versa, like
union/3, interaction/3, etc.. is missing from lists.
So if Ciao Prolog would load Logtalk it
would have everything?
Why not load small JavaScript snippets synchronously
in the browser? This one works for me. At least
some local testing works already, its not yet deployed:
let parent = "";
let cache = {};
/**
* Load a JavaScript text synchronously.
*
* @param url The url.
*/
function cludge(url) {
/* resolve and check */
if (parent !== "")
url = new URL(url, parent).href;
let map = cache[url];
if (map !== undefined)
return map;
map = {};
cache[url] = map;
/* load and execute */
let back = parent;
try {
parent = url;
let request = new XMLHttpRequest();
request.open('GET', url, false);
request.send();
let fun = new Function("exports", "require", request.responseText);
fun(map, cludge);
} finally {
parent = back;
}
return map;
}
Have Fun!
How would the world look like, if Paul Tarau would
not have written a paper about Prolog engines years
ago, but about Prolog promisses? Is there even such
a paper already? SWI-Prolog with its await/2 is quite
advanced, they have promise objects passing created
by (:=)/2 and then can be passed to await/2. In Dogelog
player promisses are still opaque, not visible in Prolog
sphere as it is actually the case in SWI-Prolog WASM.
But the idea of enginess still sticks to the mind!
Recent version of Dogelog uses import(), this is a JavaScript
function which returns a promise. Behind this promise
is loading and evaluating JavaScript code, and I could
show how to transpile WordNet to JavaScript, and then load
it via import(). Its quite fast! But can we make it parallel
without going into engines? Maybe use this syntax
for parallel import. A list wrapped into a singleton list. Or use
some flag to control it, since a default parallel behaviour
could be too dangerous?
/* Parallel Variant Syntax of Multi-Consult ? */
?- [['foo.p', 'bar.p', 'baz.p']].
Of course engines or what Tau Prolog did with tasks and
promises, could also lead to a parallel load. Maybe can get
away with a cheaper solution, not bring tasks to Dogelog
player, only juggle with import() ?
Mostowski Collapse schrieb am Donnerstag, 6. Oktober 2022 um 21:43:06 UTC+2:
How would the world look like, if Paul Tarau would
not have written a paper about Prolog engines years
ago, but about Prolog promisses? Is there even such
a paper already? SWI-Prolog with its await/2 is quite
advanced, they have promise objects passing created
by (:=)/2 and then can be passed to await/2. In Dogelog
player promisses are still opaque, not visible in Prolog
sphere as it is actually the case in SWI-Prolog WASM.
But the idea of enginess still sticks to the mind!
Dogelog Player is the avant garde of logic programming.
How long is the adoption time by other Prolog systems?
Depends, it can be 6 to 12 months. Example:
Auto-yield was explained here:
[Feb 3, 2022]
Non-Blocking Browser for Dogelog Player
https://medium.com/
It was adopted 6 months later by SWI-Prolog:
[Aug 6 2022]
ADDED: heartbeat mechanism: by setting the Prolog flag heartbeat,
the multifile predicate heartbeat/0 is called every N inferences. https://www.swi-prolog.org/
And now it got adopted by Trealla Prolog:
[March 8 2023]
Yield tweaks for Wasm port #136
https://github.com/
Now asyncifying I/O of Dogelog Player for Python.
I guess we got our head around the equivalents
of our Java Surrogate async/await constructs
"Promise" and "Coroutine". The key utilities among
asyncio are asyncio.to_thread an asyncio.run_coroutine_threadsafe,
which seem toe especially made for the two use cases.
Namely what was our Java Surrogate "Promise" wrapper,
now looks like here, what a wonderful code gem:
async def console_promise(buf, stream):
try:
res = await asyncio.to_thread(blocking_readline, stream.data)
stream.buf = res
stream.pos = 0
except IOError as err:
register_signal(buf, map_stream_error(err))
def blocking_readline(data):
return data.readline()
And what was our Java Surrogate "Coroutine" wrapper,
now looks like here, what a wonderful code gem again:
def test_sys_http_server_on(args):
[...]
obj.func = lambda req, res: baby_come_back(
launch_async(clause, buf, [req, res]), loop)
def baby_come_back(coro, loop):
future = asyncio.run_coroutine_threadsafe(coro, loop)
return future.result()
LoL
- UTF-16 native strings: Does work well with the envisioned
"latin1" payload, the range 0..255 is encoded in one 16-bit word,
which is two bytes, but most programming language already
implement clever strings:
JEP 254: Compact Strings
We propose to change the internal representation of the String class
from a UTF-16 char array to a byte array plus an encoding-flag field.
The new String class will store characters encoded either as ISO-8859-1/ Latin-1 (one byte per character), or as UTF-16 (two bytes per character), based upon the contents of the string. The encoding flag will indicate
which encoding is used.
https://openjdk.org/jeps/254
Now I have rewritten the Tic-Tac-Toe example
to be 100% Prolog. Originally the Tic-Tac-Toe example
was conceived as a first stab in exploring the
foreign function interface (FFI) of Dogelog Player
inside the browser to register JavaScript functions
that do all kind of stuff with the DOM and events.
But now I have library(markup) for DOM generation
and library(react) for events. So I rewrote Tic-Tac-Toe
using these utilities, reducing the amount of
JavaScript logic to zero. Tic-Tac-Toe is now 100% Prolog.
What also went down the drain abusing consult_async()
to do the game intialization, instead I am now using
perform_async(). So the code went from dangerous.
await consult_async(":- ensure_loaded('browser.p').");
dangerous because of possible file name quoting issues.
To this where the file name is a string object and doesn't
need to be Prolog encoded, because we don't invoke a Prolog
text encoded query but a Prolog term:
await perform_async(new Compound("ensure_loaded", ["browser.p"]));
In has far we should make some Hydration experiment.
What is Hydration. Its a new buzzword around the partially
obsolete design, to have first the HTML body in a broswer
doument and then at the end of the HTML body some scripts:
r/webdev - What is Hydration? https://www.reddit.com/r/webdev/comments/xqd4i8/what_is_hydration/
The bundle end of HTML body design has usually takes
time time(html)+time(bundle). A better deisgn is unsing
async loading and the quasi-parallelism of the browser,
and load the bundle in the head if possible. The load time
is then around max(time(bundle), time(html))). which might
give better user experience. We should try the same
for our examples, load Dogelog Player in the head. But
the Prolog text loader is not yet task safe. So this might
involve some more work until we can try it.
Also we might nevertheless want to do a little hydration
when the HTML body is read, like wiring event handlers.
Mild Shock schrieb:
Now I have rewritten the Tic-Tac-Toe example
to be 100% Prolog. Originally the Tic-Tac-Toe example
was conceived as a first stab in exploring the
foreign function interface (FFI) of Dogelog Player
inside the browser to register JavaScript functions
that do all kind of stuff with the DOM and events.
But now I have library(markup) for DOM generation
and library(react) for events. So I rewrote Tic-Tac-Toe
using these utilities, reducing the amount of
JavaScript logic to zero. Tic-Tac-Toe is now 100% Prolog.
Note because of the await in front of the
perform_async() our loading doesn't create a task yet.
It will change the current load sequence. It will
only allow that tasks create before the await get
their share of work. We would need to add one of our
create_task utilities, or use the async option of a
script tag, as recommened here for MathJax v3:
/* put this in the head */
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
The async option of a script tag is described as:
"For module scripts, if the async attribute is
present then the scripts and all their dependencies
will be fetched in parallel to parsing and evaluated
as soon as they are available." https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#async
Mild Shock schrieb:
What also went down the drain abusing consult_async()
to do the game intialization, instead I am now using
perform_async(). So the code went from dangerous.
await consult_async(":- ensure_loaded('browser.p').");
dangerous because of possible file name quoting issues.
To this where the file name is a string object and doesn't
need to be Prolog encoded, because we don't invoke a Prolog
text encoded query but a Prolog term:
await perform_async(new Compound("ensure_loaded", ["browser.p"])); >>
In has far we should make some Hydration experiment.
What is Hydration. Its a new buzzword around the partially
obsolete design, to have first the HTML body in a broswer
doument and then at the end of the HTML body some scripts:
r/webdev - What is Hydration?
https://www.reddit.com/r/webdev/comments/xqd4i8/what_is_hydration/
The bundle end of HTML body design has usually takes
time time(html)+time(bundle). A better deisgn is unsing
async loading and the quasi-parallelism of the browser,
and load the bundle in the head if possible. The load time
is then around max(time(bundle), time(html))). which might
give better user experience. We should try the same
for our examples, load Dogelog Player in the head. But
the Prolog text loader is not yet task safe. So this might
involve some more work until we can try it.
Also we might nevertheless want to do a little hydration
when the HTML body is read, like wiring event handlers.
Mild Shock schrieb:
Now I have rewritten the Tic-Tac-Toe example
to be 100% Prolog. Originally the Tic-Tac-Toe example
was conceived as a first stab in exploring the
foreign function interface (FFI) of Dogelog Player
inside the browser to register JavaScript functions
that do all kind of stuff with the DOM and events.
But now I have library(markup) for DOM generation
and library(react) for events. So I rewrote Tic-Tac-Toe
using these utilities, reducing the amount of
JavaScript logic to zero. Tic-Tac-Toe is now 100% Prolog.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 491 |
Nodes: | 16 (2 / 14) |
Uptime: | 147:13:24 |
Calls: | 9,694 |
Calls today: | 4 |
Files: | 13,732 |
Messages: | 6,178,671 |