module fact. import obj. type get Value -> o. type g int -> o. type point o. type zero? o. type succ o. type pred o. type intclass o. type writeobj Identifier -> o. (new intclass St Id || anti --> anti || object Id St Ms):- N = (M \ (pi S \ pi P \ pi Q \ (call Id pred || frozen Id S (P & Q) --> anti || object Id S (M & Q)) )), Ms = (pi S \ pi M \ pi T \ ( (write "ZERO!" >> call Id zero? || frozen Id S M --> anti || object Id S M) & (call Id succ || frozen Id S (M & T) --> anti || object Id S ((N M) & T)) )). type factclass o. type slave o. type receiver o. type eval int -> o. type st int -> Identifier -> o. type fact int -> Identifier -> o. (new slave St Id || anti --> anti || object Id St Ms):- Ms = (pi N \ pi N1 \ pi N2 \ pi Ms \ pi O \ ((N2 is N1 * N) >> call Id (eval N1) || frozen Id (st N O) Ms --> send O (eval N2) || anti) ). (new factclass St Id || anti --> anti || object Id St Ms):- Ms = (pi S \ pi M \ pi N\ pi O\ pi T\ pi N1 \ (((N =< 2) >> call Id (fact N O) || frozen Id S M --> send O (eval N) || object Id S M) & ((N > 2, N1 is N - 1) >> call Id (fact N O) || frozen Id S M --> (pi id \(new slave (st N O) id | send Id (fact N1 id))) || object Id S M ))). (new receiver St Id || anti --> anti || object Id St Ms):- Ms = (pi N \ pi S \ pi M \ ((print "\n Result: ",write N,print "\n") >> call Id (eval N) || frozen Id S M --> anti || anti ) ). type stack o. type pop Element -> o. type push Element -> o. type a list Element -> o. (new stack St Id || anti --> (anti || object Id (a nil) Ms)):- Ms = (pi S \ pi M \ pi El \ ((call Id (pop El) || frozen Id (a (El::S)) M --> anti || object Id (a S) M) & (call Id (push El) || frozen Id (a S) M --> anti || object Id (a (El::S)) M))). initial anti. type start o. start:- spyon => ehhfsolve ( new intclass anti 1 | send 1 zero? | send 1 succ | send 1 pred | send 1 zero?). start:- ehhfsolve ( new intclass anti 1 | send 1 zero? | send 1 succ | send 1 pred | send 1 zero?). start:- ehhfsolve ( new intclass anti 1 | send 1 zero? | send 1 pred). start:- spyon => ehhfsolve ( new receiver anti 1 | new factclass anti 2 | send 2 (fact 4 1)). start:- ehhfsolve (new stack anti 1 | writeobj 1 | break 1 St).