Logical assignment of Prolog terms
This is an almost portable, almost logical implementation of destructive assignment.
- Assignable terms and logical assignment
assignable(Var) makes Var an assignable term. Initial state of it
is an empty assignable term.
An assignable terms have a value, and the value may be changed.
- assignable(A) : A is an empty assignable term.
- assignable(B,a) : B is an assignable term, and initial value is atom a.
- assignable(C,p(1.2)) : initial value of C is p(1.2).
- X <= V makes the value of assignable term X to V.
(<=)/2 is deterministic, and on backtracking, the value of X
backs up to the previous value of X at the choice point.
X => V unifies V to the current value of assignable term X.
If X is empty, simply fails.
- X <+ V, is similar to X <= V, makes the value of assignable term
X to V,then commit it. On backtracking, the previous value of X never backs
up. X will be empty.
After assignable(X), X<=b, X<=c,X<=d, X => D :
D == d
- Unification between assignable terms.
Also, the results of decomposing an assignable term using
arg/3,functor/3,=../2 are undefined.
01/03/2005 Error checking and and <+compatibility with Prolog implementations.
12/31/2004 First distribution.
is the implementation (using setarg/3).
And the pure logical subset
implementation is also available at
Implementations and examples are checked against
distributed under Open Software License version 2.1, with NO WARRANTY.
- Example programs
- Finite state machine(download)
A state machine holds its status in an assignable term.
fsm(States,Initial, FSM), % FSM is state holder
fsm_transition(FSM,0), % transition with events
- List enumerator(download)
List enumeration done without backtracking.
listNextMember(E,L1), % L1 == a
listNextMember(E,L2), % L2 == b
listNextMember(E,L3), % L3 == c
List permutation example
listPermute(P,L1), % L1==[a,b,c]
listPermute(P,L2), % L2==[a,c,b]
listPermute(P,L3), % L3==[b,a,c]
- Infinite loop(download)
Memory consumed with assignable terms should be garbage collected.
(C) Nobukuni Kino, KLS Research, Inc.
Comments and questions are welcome. firstname.lastname@example.org