diff -r 3267acc1f97f -r b16dfc467b67 scala/turing.scala --- 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)})