Comments (9)
Happy to add something in but I think will be a bit of work. Maybe on the weekend.
from trealla.
Turns out it was pretty easy to do once I started looking at it. Now providing a SWI-Prolog compatible...
with_output_to(chars(Cs), Goal) :-
setup_call_cleanup(
'$capture_output',
once(Goal),
'$capture_output_to_chars'(Cs)
), !.
but you can roll your own without once/1.
from trealla.
I have added '$capture_error'/0 and '$capture_error_to_chars'/1 to enable capture of user_error. It should be possible now to capture trace info (which goes to stderr) and display in a separate window.
from trealla.
Much appreciated. The current workarounds are effective so please take your time 🙂
from trealla.
Excellent! I have one question, more of a Prolog question, but:
query(Query, Status, Output) :-
%'$capture_output',
( call(Query) % ← how can I get this to call $capture_output each time before backtracking?
*-> Status = success
; Status = failure
),
'$capture_output_to_chars'(Output).
I can see why SWI shoves the once/1
into there now, haha.
I feel like I am definitely fighting against what you are supposed to do in Prolog, but I'm not sure how to accomplish this otherwise 🤔
from trealla.
from trealla.
Good point... I tried that but I wasn't able to get it to work 🤔
However, this does work (borrowing a technique from SWI's manual):
js_ask :-
setup_call_cleanup(
'$capture_output',
catch(
( query(Query, Status, Output) ),
Error,
Status = error
),
'$capture_output_to_chars'(_) % eat spurious last capture
)
% ...
query(Query, Status, Output) :-
( call(Query)
*-> Status = success
; Status = failure
),
'$capture_output_to_chars'(Output),
( true ; '$capture_output', fail ).
I'm probably just doing something dumb.
from trealla.
OK I can confirm it is working well. I will integrate it into the WASM stuff soon. Thanks a bunch.
I ran into this issue again: #46 (comment) but still not able to isolate it. Something can trigger the backtracking to work strangely. Capture stuff is good though.
I will make a separate issue for that.
from trealla.
from trealla.
Related Issues (20)
- Somewhat unexpected error context HOT 1
- Meta predicate goal expansion HOT 2
- Segmentation fault (core dumped)
- FYI: Trealla trashes effort to port a C-compiler HOT 11
- Pressing the tab key = segmentation fault HOT 3
- CLPZ: `#<==>/2` crashing (and consequently: `clpz_t/2`, `#=/3`, `#</3`) HOT 6
- CLPZ: Comparison HOT 3
- current_op/3 shuttered
- `phrase_to_stream/2` (consequently: `phrase_to_file/2`) total memory consumption with a mega-string HOT 1
- is/2 type_error disregarded HOT 1
- CLPZ:monotonic: segfault
- CLPZ: Error: syntax error unexpected HOT 2
- segmentation fault in warehouse test HOT 5
- phrase/2 instantiation_error? HOT 1
- 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
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.