Created
April 3, 2021 18:31
Star
You must be signed in to star a gist
Pure way for tracking state of variables in Prolog
This file contains 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: