Comments (16)
from trealla.
from trealla.
from trealla.
from trealla.
Awesome, much appreciated. I did some testing with the JS library and it's looking good, was able to iterate through results just as imagined.
I did find an odd bug that makes my toplevel act weird sometimes, trying to isolate it at the moment.
Upon backtracking it seems like an argument to a predicate gets replaced with the wrong variable:
person(socrates).
person(plato).
mortal(X) :- person(X).
js_toplevel
module from here: https://github.com/guregu/trealla/blob/c1bc80678d7dd3d975ab81b32f69e080b7a040c9/library/js_toplevel.pl
$ ./tpl --ns -g 'use_module(library(js_toplevel)), js_ask("mortal(X)")' soc.pl
��{"result":"success","answer":{"X":"socrates"}}
% expected plato as well
Maybe an issue with backtracking on variable_names
variables from read_term?
I'll dig some more.
[user:4] CALL js_ask("mortal(X)")
[js_toplevel:5] CALL catch(read_term_from_chars(_0,[variable_names(_1)],"mortal(X)"),_3,(write('\x2\\x3\'),write_result(error,_3),flush_output))
[js_toplevel:6] CALL '$catch'(call(read_term_from_chars(_0,[variable_names(_1)],"mortal(X)")),_3,call((write('\x2\\x3\'),write_result(error,_3),flush_output)))
[js_toplevel:7] EXIT '$catch'(call(read_term_from_chars(_0,[variable_names(_1)],"mortal(X)")),_3,call((write('\x2\\x3\'),write_result(error,_3),flush_output)))
[js_toplevel:8] CALL call(read_term_from_chars(_0,[variable_names(_1)],"mortal(X)"))
[js_toplevel:9] EXIT call(read_term_from_chars(_0,[variable_names(_1)],"mortal(X)"))
[js_toplevel:10] CALL read_term_from_chars(_0,[variable_names(_1)],"mortal(X)")
[js_toplevel:11] EXIT read_term_from_chars(mortal(_9),[variable_names(['X'=_9])],"mortal(X)")
[js_toplevel:12] CALL '$drop_barrier'
[js_toplevel:13] EXIT '$drop_barrier'
[js_toplevel:14] CALL '$block_catcher'(0)
[js_toplevel:15] EXIT '$block_catcher'(0)
[js_toplevel:16] EXIT catch(read_term_from_chars(mortal(_9),[variable_names(['X'=_9])],"mortal(X)"),_3,(write('\x2\\x3\'),write_result(error,_3),flush_output))
[js_toplevel:17] CALL query(mortal(_9),['X'=_9],_4,_5)
[js_toplevel:18] CALL write('\x2\')
�[js_toplevel:19] EXIT write('\x2\')
[js_toplevel:20] CALL catch(mortal(_9),_11,true)
[js_toplevel:21] CALL '$catch'(call(mortal(_9)),_11,call(true))
[js_toplevel:22] EXIT '$catch'(call(mortal(_9)),_11,call(true))
[js_toplevel:23] CALL call(mortal(_9))
[js_toplevel:24] EXIT call(mortal(_9))
[js_toplevel:25] CALL mortal(_9)
[user:26] CALL person(_9) <------------------------------------------ normal
[user:27] EXIT person(socrates)
[js_toplevel:28] CALL '$drop_barrier'
[js_toplevel:29] EXIT '$drop_barrier'
[js_toplevel:30] CALL '$block_catcher'(1)
[js_toplevel:31] EXIT '$block_catcher'(1)
[js_toplevel:32] EXIT person(socrates)
[js_toplevel:33] CALL '$soft_cut'
[js_toplevel:34] EXIT '$soft_cut'
[js_toplevel:35] CALL _12=true
[js_toplevel:36] EXIT true=true
[js_toplevel:37] CALL write('\x3\')
�[js_toplevel:38] EXIT write('\x3\')
[js_toplevel:39] CALL query_status(true,_11,_4)
[js_toplevel:40] CALL nonvar(_11)
[js_toplevel:41] FAIL nonvar(_11)
[js_toplevel:42] REDO query_status(true,_11,_4)
[js_toplevel:43] EXIT query_status(true,_11,success)
[js_toplevel:44] CALL nonvar(_11)
[js_toplevel:45] FAIL nonvar(_11)
[js_toplevel:46] CALL _5=['X'=socrates]
[js_toplevel:47] EXIT ['X'=socrates]=['X'=socrates]
[js_toplevel:48] EXIT query_status(true,mortal(socrates),success)
[js_toplevel:49] CALL write_result(success,['X'=socrates])
[js_toplevel:50] CALL solution_json(['X'=socrates],_20)
[js_toplevel:51] CALL maplist(var_json,['X'=socrates],_23)
[js_toplevel:52] CALL maplist_(['X'=socrates],_23,var_json)
[js_toplevel:53] CALL call(var_json,'X'=socrates,_29)
[js_toplevel:54] EXIT call(var_json,'X'=socrates,_29)
[js_toplevel:55] CALL var_json('X'=socrates,_29)
[js_toplevel:56] CALL atom_chars('X',_33)
[js_toplevel:57] EXIT atom_chars('X',"X")
[js_toplevel:58] CALL term_json(socrates,_35)
[js_toplevel:59] CALL atom(socrates)
[js_toplevel:60] EXIT atom(socrates)
[js_toplevel:61] CALL atom_chars(socrates,_37)
[js_toplevel:62] EXIT atom_chars(socrates,"socrates")
[js_toplevel:63] CALL !
[js_toplevel:64] EXIT !
[js_toplevel:65] EXIT term_json(socrates,string("socrates"))
[js_toplevel:66] CALL '$drop_barrier'
[js_toplevel:67] EXIT '$drop_barrier'
[js_toplevel:68] CALL maplist_([],_31,var_json)
[js_toplevel:69] EXIT maplist_([],[],var_json)
[js_toplevel:70] CALL once(phrase(json_chars(pairs([string("result")-string("success"),string("answer")-pairs([string(...)-string(...)])])),_21))
....... json DCG spam ........
[js_toplevel:1900] REDO call(mortal(_9))
[js_toplevel:1901] FAIL call(mortal(_9))
[js_toplevel:1902] REDO '$catch'(call(mortal(_9)),_11,call(true))
[js_toplevel:1903] FAIL '$catch'(call(mortal(_9)),_11,call(true))
true
; [js_toplevel:1896] REDO '$block_catcher'(1)
[js_toplevel:1897] FAIL '$block_catcher'(1)
[user:1898] REDO person(['X'=_9]) <---------------- got replaced with wrong var?
[user:1899] FAIL person(['X'=_9])
[js_toplevel:1900] REDO call(mortal(_9))
[js_toplevel:1901] FAIL call(mortal(_9))
[js_toplevel:1902] REDO '$catch'(call(mortal(_9)),_11,call(true))
[js_toplevel:1903] FAIL '$catch'(call(mortal(_9)),_11,call(true))
from trealla.
Playing around with it, you can remove the soft cut and still trigger it, seems that nested call/1
in catch/3
might be the culprit.
Moving the try/catch bit upwards fixes it.
Diff here: guregu@8d69193
Tried creating a more minimal repro but was not successful.
Anyway, this should be enough to get the basics working. JS is looking good, will release a new version in a little bit.
from trealla.
It works very nicely. I released a new version of the JS lib that takes advantage of it. It's very close to hitting v1.0 I think!
I think the final thing the WASM stuff needs is having this work kind of like task/N, or fork/0, except instead of using wait/0 we manually prod along each task (subquery) with redo requests from the host. We don't have to worry about synchronization here, we can leave it up to the host to deal with that.
The use case here is to let people asynchronously run queries against the same knowledge base. In the browser world it can be pretty unpredictable the order things run in sometimes.
// contrived example for current impl
const a = pl.query("between(0,9,X).");
const b = pl.query("between(10,19,N).");
await a.next();
await b.next();
await a.next(); // throws (invalid iterator)
from trealla.
from trealla.
Yes, please. That would be great. Feel free to tweak the API however you'd like, I can adapt the code from the current WASM stuff easily to it. Query handle can be anything as long as WASM can pass it (any pointer, or int32/64).
from trealla.
It works wonderfully! Thank you so much @infradig. I'll release the updated libs soon.
Just a tiny bit of polishing on my end and I think we are ready for trealla-js v1.0!
I'll also update the Go stuff.
P.S.: love the name SMC ;)
I think this will be a big plus for people looking to do logic stuff on the web. Trealla is a very compact binary so it's perfect for embedding. Exciting times ahead.
from trealla.
I've cut beta releases for the JS and Go libs and they are looking good. I'm going to try to nail down some nuances in the toplevel API before the big one dot zero (as in here guregu/trealla-js#4).
Feel free to merge the changes for the redo API into main. API is solid and I don't foresee needing anything more.
from trealla.
Is it OK to use yield/0
with the new query API? I think I can use it to implement some async stuff on the JS side.
from trealla.
I added an API to grab the subquery's yielded
flag and made this:
https://php.energy/trealla.html?src=%3A-+use_module%28library%28format%29%29.%0A%0Afetch%28URL%2C+Content%29+%3A-%0A++phrase%28format_%28%22return+fetch%28%7Ew%29.then%28x+%3D%3E+x.json%28%29%29%3B%22%2C+%5BURL%5D%29%2C+JS%29%2C%0A++js_eval_json%28JS%2C+Content%29.&q=fetch%28%22https%3A%2F%2Fhttpbin.org%2Fget%22%2C+X%29.&v=0
Kinda can't believe it works! It was way easier than I expected to get async to work.
It's a testament to the quality of this code base, thanks a bunch!
More here: guregu/trealla-js#17 (comment)
from trealla.
from trealla.
from trealla.
from trealla.
Related Issues (20)
- phrase/2 segfault HOT 1
- does this terminate, i.e. model finder HOT 8
- Application-specific Comparsion HOT 4
- Odd parser bug HOT 8
- Syntax error undetected
- op/3 Operator deactivation fault
- garbage collection and keysort/2 HOT 12
- Lists any length core dump HOT 2
- Listing readout inapplicable HOT 12
- atom_chars/2 string leak HOT 8
- TCO examples HOT 2
- non-linear slowdown in A* search HOT 4
- _Vars are not printed HOT 4
- Subscript and superscript Unicode HOT 7
- Works on Scryer but not Trealla HOT 2
- Segmentation Dump with NOFFI=1 NOSSL=1 NOTHREADS=1 ISOCLINE=1 Enabled HOT 1
- arg/3 + string weirdness HOT 2
- freeze/2 not playing well with negation HOT 6
- Module visibility for attributes incorrect? HOT 2
- Callligraphic script not unparsed like it is parsed?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trealla.