lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Sep 28, 2013 at 9:22 PM, Francisco Olarte <folarte@peoplecall.com> wrote:
Hi:

On Sat, Sep 28, 2013 at 2:55 PM, Jayanth Acharya <jayachar88@gmail.com> wrote:
> Thanks Matt. While I understand why your snippet works, I still don't
> understand why mine doesn't. Anyhow, I shall fall back to the FSM code in
> the Lua wiki link in my OP -- now that I understand it bit better, would
> still be a good thing to figure out the issue with my snippet.

If you 'unroll' the table building you can see it, the original snippet:

fsm = { s1 = { e1 = { 's2', a1}},
        s2 = { e2 = { 's3', a2}},
        s1 = { e2 = { 's1', nil}},
        s2 = { e3 = { 's4', a3}}
      }

Would be something like:
fsm={}
fsm[s1] = { e1 = { 's2', a1}},
fsm[s2] = { e2 = { 's3', a2}}
fsm[s1] = { e2 = { 's1', nil}}  <==== Overwriting previous value of fsm[s1],
fsm[s2] = { e3 = { 's4', a3}}


Like I said, it was indeed a slow day. Understood it now. Basically, the point at which we overwrite the previous value of fsm[s1], we break the fsm[s1][e1] relation as well, as the new relation become fsm[s1][e2] ! Had missed this aspect.
 
While the fixed ( reindented to better show the difference ) one:

 fsm = { s1 = { e1 = { 's2', a1},  e2 = { 's1', nil} },
            s2 = { e2 = { 's3', a2}, e3 = { 's4', a3}}
      }

would be something like:

fsm={}
fsm[s1] = { e1 = { 's2', a1}, e2 = { 's1', nil}}
fsm[s2]=  { e2 = { 's3', a2}, e3 = { 's4', a3}}

This part is absolutely and complete clear :-)
 

Regards.
 Francisco Olarte.