Mercurial > hg > Applications > Tokio
view Examples/etc/talk @ 0:cfb7c6b24319
Initial revision
author | kono |
---|---|
date | Thu, 30 Aug 2007 14:57:44 +0900 |
parents | |
children |
line wrap: on
line source
% % Talk Program for Tokio % Tue Jul 5 01:18:04 JST 1988 talk(A,B) :- #key(A,In1),#crt(A,Out1), #key(B,In2),#crt(A,Out2), Buffer1 = [], Buffer2 = [], merge_dequeue(In1,In2,Out1,Buffer1), merge_dequeue(In2,In1,Out2,Buffer2). key(Who,Input) :- write(Who),write(':in:'), read(Input). crt(Who,Output) :- write(Who),write(':out:'),write(Output),nl. merge_dequeue(In1,In2,Out,Buffer) :- merge(In1,In2,Buffer), @ dequeue(Out,Buffer), @ @ merge_dequeue(In1,In2,Out,Buffer). merge(In1,In2,Buffer) :- In1 = none, In2 = none,!, @Buffer = Buffer. merge(In1,In2,Buffer) :- In1 = none, !, ap(Buffer,[In2],@Buffer). merge(In1,In2,Buffer) :- In2 = none, !, ap(Buffer,[In1],@Buffer). merge(In1,In2,Buffer) :- % non deterministic choice ap(Buffer,[In2],@Buffer). merge(In1,In2,Buffer) :- ap(Buffer,[In1],@Buffer). dequeue(Out, Buffer) :- Buffer = [],!. dequeue(Out, Buffer) :- Buffer = [Out|@Buffer]. ap(Nil,X,X1) :- Nil = [], X = X1. ap(HX,Z,HY) :- HX = [H|X], HY = [H|Y], ap(X,Y,Z).