aboutsummaryrefslogtreecommitdiff
path: root/turinglog.icl
diff options
context:
space:
mode:
authorCamil Staps2015-09-03 22:50:01 +0200
committerCamil Staps2015-09-03 22:50:01 +0200
commit3b916056cdbd070c8ea70415a0f21b809c3c54c3 (patch)
tree2af71efaf06b00a4e9c44fa0bdf67ba420849441 /turinglog.icl
parentUpdate readme with latest changes (diff)
Turinglog programHEADmaster
Diffstat (limited to 'turinglog.icl')
-rw-r--r--turinglog.icl38
1 files changed, 38 insertions, 0 deletions
diff --git a/turinglog.icl b/turinglog.icl
new file mode 100644
index 0000000..273c70b
--- /dev/null
+++ b/turinglog.icl
@@ -0,0 +1,38 @@
+module turinglog
+
+import StdEnv
+import TuringMachines
+
+Start :: *World -> *World
+Start w
+# (io,w) = stdio w
+# m = initTuringMachine machine tape
+# io = fwrites (toString m +++ "\n") io
+# io = loop m io
+# (ok,w) = fclose io w
+| not ok = abort "Couldn't close stdio\n"
+| otherwise = w
+where
+ loop m f
+ # m = step m
+ # f = fwrites (toString m +++ "\n") f
+ | m.running == Running = loop m f
+ | otherwise = f
+
+tape :: Tape Char
+tape = [Just c \\ c <- fromString "abbaba"]
+
+machine :: TuringMachine Char
+machine = { alphabet = ['a', 'b'],
+ inputs = ['a', 'b'],
+ transition = f }
+where
+ f :: Int (Maybe Char) -> TuringMachineMove Char
+ f 0 Nothing = Step 1 Nothing Right
+ f 1 Nothing = Step 2 Nothing Left
+ f 1 (Just 'a') = Step 1 (Just 'b') Right
+ f 1 (Just 'b') = Step 1 (Just 'a') Right
+ f 2 (Just 'a') = Step 2 (Just 'a') Left
+ f 2 (Just 'b') = Step 2 (Just 'b') Left
+ f _ _ = Halt
+