From 4868efbf0e080d204172c17a3feb5ee42b066c9e Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 3 Sep 2015 20:54:15 +0200 Subject: More compact & nicer toString for states; added ! for step functions; bugfix for tape length The new toString takes only one line and is a better reproduction of the notation from Sudkamp, Languages and Machines, 1997. The IterableClass functions now have ! on input types that are iterated, so that these arguments are computed for sure. There was a bug (!! index too large or the like) for some machines that 'walked off the tape' on the right side. The tape is now auto- matically extended with Nothing (blank) cells. When the machine walks off the tape on the *left*, the machine still terminates abnormally. --- TuringMachines.icl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'TuringMachines.icl') diff --git a/TuringMachines.icl b/TuringMachines.icl index b37233c..f13ca7d 100644 --- a/TuringMachines.icl +++ b/TuringMachines.icl @@ -30,7 +30,10 @@ where instance toString (TuringMachineState a) | toString a where toString st=:{state,tapeHead,tape,running} - = toString running +++ " turing machine in state " +++ toString state +++ ", tape head at " +++ toString tapeHead +++ ".\nTape: " +++ toString tape + = toString (take tapeHead tape) +++ + "[q" +++ toString state +++ "]" +++ + toString (drop tapeHead tape) +++ + " (" +++ toString running +++ ")" instance == Direction where @@ -55,6 +58,7 @@ instance step (TuringMachineState a) | == a where step st=:{machine,state,tapeHead,tape,running} | running <> Running = st + # tape = if (length tape < tapeHead + 1) (tape ++ [Nothing]) tape # move = machine.transition state (tape!!tapeHead) | move == Halt = {st & running = Normal} # (Step state write dir) = move -- cgit v1.2.3