/*-------------------------------------------------------------------------
    program: toggling a switch
    file:    switch2
    date:    December 97
    updated: Pablo Lopez (lopez@lcc.uma.es)
             Dept. of CS
             University of Malaga, SPAIN

    notes:   This code is a Forum version of a Lolli example originally
             proposed by Joshua S. Hodas and Dale Miller in
             "Logic Programming in a Fragment of Intuitionistic Linear Logic"
             Information and Computation, 110(2), pp. 327-365, 1994.

    sample goals:
        switch2(on,1,off).
        switch2(S1,3,S2).
-------------------------------------------------------------------------*/

module switch2.

toggle(N) # state(on)  <= N > 0
                       <= N_1 is N-1
                       *- toggle(N_1) # state(off).

toggle(N) # state(off) <= N > 0
                       <= N_1 is N-1
                       *- toggle(N_1) # state(on).

toggle(0) # state(S) # final(S).

switch2(Initial,Ntoggles,End) *-
     state(Initial) # toggle(Ntoggles) # final(End).


