automata.scala
changeset 35 487b0c0aef75
parent 34 eeff9953a1c1
child 43 93fc2f18e129
--- a/automata.scala	Sun Oct 14 23:41:49 2012 +0100
+++ b/automata.scala	Wed Oct 17 00:58:06 2012 +0100
@@ -69,15 +69,15 @@
 type States = Set[State]
 type Transition =  Map[(State, Char), State]
 
+// we use as an alphabet all lowercase letters
+val alphabet = "abcdefghijklmnopqrstuvwxyz".toSet
+
 def goto(q: State, c: Char, qs: States, delta: Transition) : (States, Transition) = {
-  val qc : State = der(q, c)
-  if (qs.contains(qc)) (qs, delta + ((q, c) -> q))
-  else explore(qs + qc, delta + ((q, c) -> qc), qc)
+  val q_der : State = der(q, c)
+  if (qs.contains(q_der)) (qs, delta + ((q, c) -> q))
+  else explore(qs + q_der, delta + ((q, c) -> q_der), q_der)
 }
 
-// we use as an alphabet all lowercase letters
-val alphabet = "abcdefghijklmnopqrstuvwxyz".toSet
-   
 def explore (qs: States, delta: Transition, q: State) : (States, Transition) =
   alphabet.foldRight[(States, Transition)] (qs, delta) ((c, qsd) => goto(q, c, qsd._1, qsd._2))