scala/turing.scala
changeset 209 b16dfc467b67
parent 194 fc2a5e9fbb97
child 210 5e2e576fac7c
--- a/scala/turing.scala	Fri Mar 01 23:46:02 2013 +0000
+++ b/scala/turing.scala	Sat Mar 02 10:42:39 2013 +0000
@@ -46,8 +46,11 @@
 
 // standard tapes
 object Tape {
-  def apply(ns: Int*) : Tape = 
-    Tape(Nil, ns.map(n => Oc * (n + 1)).reduceLeft(_ ::: List(Bk) ::: _))
+  def apply(ns: List[Int]) : Tape = 
+   Tape(Nil, ns.map(n => Oc * (n + 1)).reduceLeft(_ ::: List(Bk) ::: _))
+
+  def apply(ns: Int*) : Tape = apply(ns.toList)
+    
 }
 
 // configurations
@@ -60,8 +63,9 @@
 // Turing machines
 case class TM(p: Prog) {
 
-  // simple composition
+  // composition
   def ++ (that: TM) = TM(this.p ::: that.p)
+  def :+ (that: TM) = this.adjust ++ that.shift(this.p.length / 2 + 1)
 
   def shift(n: Int) =
     TM(p.map{case (a, s) => (a, if (s == 0) 0 else s + n)})