Skip to content

Blackboard and attributes on a naked variable #1359

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

Open
infradig opened this issue Mar 27, 2025 · 3 comments
Open

Blackboard and attributes on a naked variable #1359

infradig opened this issue Mar 27, 2025 · 3 comments
Labels

Comments

@infradig
Copy link

This works...

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.21-90-ge96c60c-DIRTY)
?- freeze(A,writeln(here)), nb_setval(abc, f(A)).
freeze(A, writeln(here)).
?- b_getval(abc,A).
A = f(_A),
freeze(_A, writeln(here)).
?- b_getval(abc,A), A=f(123).
here
A = f(123).

but this doesn't...

?- freeze(A,writeln(here)), nb_setval(abc, A).
freeze(A, writeln(here)).
?- b_getval(abc,A).
freeze(A, writeln(_)).
?- b_getval(abc,A), A=123.
_2576
A = 123.
@JanWielemaker
Copy link
Member

The toplevel loop is a backtracking loop, so all backtrackable actions are lost between queries. You can set the Prolog flag toplevel_mode to recursive to turn the toplevel into a recursive loop.

@infradig
Copy link
Author

Sorry, I meant to use non-backtrackable, pasted the wrong text...

?- freeze(A,writeln(here)), nb_setval(abc, f(A)).
freeze(A, writeln(here)).
?- nb_getval(abc,A), A=f(123).
here
A = f(123).

?- freeze(A,writeln(here)), nb_setval(abc, A).
freeze(A, writeln(here)).
?- nb_getval(abc,A), A=123.
_6760
A = 123.
?- 

@JanWielemaker
Copy link
Member

There is indeed something wrong:

?- freeze(A,writeln(here)), nb_setval(abc, A).
freeze(A, writeln(here)).

?- nb_getval(abc, X), get_attrs(X, L).
L = att(freeze, user:writeln(_A), []),
freeze(X, writeln(_A)).

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

No branches or pull requests

2 participants