package examples.turing; import static examples.turing.Direction.*; public handler turing { constraint delta( +Object StateId, char Symbol, // input +Object NewStateId, char NewSymbol, Direction // output ); constraints current_state(+Object Id), head(+Object HeadId), cell(+Object Id, char Symbol, +Object Left, +Object Right), move(Direction, +Object CellId, +Object Left, +Object Right); rules { trans @ delta(S,G,Sp,Gp,Dir) \ current_state(S), head(Cell), cell(Cell,G,Left,Right) <=> current_state(Sp), cell(Cell,Gp,Left,Right), move(Dir,Cell,Left,Right). local +Object L; move(LEFT,Cell,null,R), cell(Cell,G,null,R) <=> L = new Object(), cell(Cell,G,L,R), cell(L,'#',null,Cell), head(L). move(LEFT,Cell,L,_) <=> L != null | head(L). local +Object R; move(RIGHT,Cell,L,null), cell(Cell,G,_,_) <=> R = new Object(), cell(Cell,G,L,R), cell(R,'#',Cell,null), head(R). move(RIGHT,Cell,_,R) <=> R !== null | head(R). } }