Created
April 3, 2021 18:31
-
-
Save jeshan/140ff4c039522329eae428b69732a01c to your computer and use it in GitHub Desktop.
Pure way for tracking state of variables in Prolog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% get_value(Value, History) | |
% History tracks values set for variable | |
get_value(Val, List) :- | |
nonvar(List), % just so that fails when nothing added yet. | |
nextto(t(Val), Var, List), | |
var(Var), | |
!. | |
available_spot(X, History) :- | |
once((member(X, History), var(X))). | |
add_value(Val, History) :- | |
available_spot(X, History), | |
t(Val) = X. |
Code is released to the public domain
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example outputs: