diff options
author | Camil Staps | 2015-09-03 20:54:15 +0200 |
---|---|---|
committer | Camil Staps | 2015-09-03 20:54:15 +0200 |
commit | 4868efbf0e080d204172c17a3feb5ee42b066c9e (patch) | |
tree | eb00a0bce117c5fc466b0ef1d67a212421cef16c /TuringMachines.icl | |
parent | Initial commit (diff) |
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.
Diffstat (limited to 'TuringMachines.icl')
-rw-r--r-- | TuringMachines.icl | 6 |
1 files changed, 5 insertions, 1 deletions
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 |