Git Product home page Git Product logo

Comments (9)

infradig avatar infradig commented on July 28, 2024 1

Happy to add something in but I think will be a bit of work. Maybe on the weekend.

from trealla.

infradig avatar infradig commented on July 28, 2024 1

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.

infradig avatar infradig commented on July 28, 2024 1

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.

guregu avatar guregu commented on July 28, 2024

Much appreciated. The current workarounds are effective so please take your time 🙂

from trealla.

guregu avatar guregu commented on July 28, 2024

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.

infradig avatar infradig commented on July 28, 2024

from trealla.

guregu avatar guregu commented on July 28, 2024

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.

guregu avatar guregu commented on July 28, 2024

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.

infradig avatar infradig commented on July 28, 2024

from trealla.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.