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.

[Example]

After assignable(X), X<=b, X<=c,X<=d, X => D :

D == d

- Unification between assignable terms.

Undefined.

Also, the results of decomposing an assignable term using arg/3,functor/3,=../2 are undefined.

- History

01/03/2005 Error checking and and <+compatibility with Prolog implementations.

12/31/2004 First distribution.

- Implementation

http://www.kprolog.com/en/logical_assignment/assignable.pl

is the implementation (using setarg/3).

And the pure logical subset implementation is also available at

http://www.kprolog.com/en/logical_assignment/assign_logial.pl

Implementations and examples are checked against SWI-Prolog, GNU-Prolog and K-Prolog, 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 fsm_transition(FSM,1), fsm_transition(FSM,1),

- List enumerator(download)

List enumeration done without backtracking.

listEnumerator(E,[a,b,c,d,e,f]), listNextMember(E,L1), % L1 == a listNextMember(E,L2), % L2 == b listNextMember(E,L3), % L3 == c

- Listpermutor(download)

List permutation example

listPermutor(P,[a,b,c]), 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.

- Finite state machine(download)

Enjoy,

(C) Nobukuni Kino, KLS Research, Inc.

Comments and questions are welcome. kino@kprolog.com