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

Calling assertz/1 with stream-based clause #2638

Open
thierrymarianne opened this issue Oct 21, 2024 · 3 comments
Open

Calling assertz/1 with stream-based clause #2638

thierrymarianne opened this issue Oct 21, 2024 · 3 comments

Comments

@thierrymarianne
Copy link

thierrymarianne commented Oct 21, 2024

Hello,

I've tried to call assertz/1 by passing it a clause depending on a stream as follows:

test :-
	open('./learn/test-page.dj', read, Stream),
	assertz(stream('test', Stream)).

:- initialization(test).

Is there something i could do to make it work?

I wonder if some additional case(s) could be added to heap.rs.

The broader context is that I'm trying to make the prolog-based interactive prover LPTP to work with Scryer Prolog but I could not go past those lines. I started from GNU Prolog configuration file where assert/1 is declared with assertz/1 in its body.

@hurufu
Copy link
Contributor

hurufu commented Oct 22, 2024

Panic should be fixed indeed, but you don't need to allocate stream handle on a heap manually. All streams can be inspected using stream_property/2. So in your case just leave the following in your program:

:- initialization(test).
test :-
	open('./learn/test-page.dj', read, Stream).

And then when you want to retrieve stream handle just do:

stream_property(Stream, file_name('./learn/test-page.dj')).

@hurufu
Copy link
Contributor

hurufu commented Oct 22, 2024

Even better is to use stream alias:

:- initialization(setup_stream).
setup_stream :-
    open('file.pl', read, _, [alias(my_file)]).

And then you can use that alias freely throughout your program for example using read_term(my_file, T, []).

@thierrymarianne
Copy link
Author

thierrymarianne commented Oct 22, 2024

Thank you. That helps!

Yesterday, I also tried to unwrap the stream alias Option<Atom> before converting it as a Literal::Atom on the side to circumvent temporarily the encountered issue even though I can only assume proceeding as such makes for very little sense at heap.rs:76. However, I'd be happy to submit a proper fix with a little guidance.

HeapCellValueTag::Cons case was separated from loader.rs:1399 only so that I could make sure where the panic came from.

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

No branches or pull requests

2 participants