Almost exactly 10 years ago, on 2004-03-19, J introduced the
;:
dyad "Sequential Machine" (aka: "Finite State
Machine (FSM)" or "Deterministic Finite Automaton (DFA)".) Time to
finally learn it, not just by roughly looking at
the definition (as done back then) but by actually trying it
out.
This turned out much more difficult than expected. All in all, I needed three days/attempts (>1h each) tackling this DoJ entry before I was greeted with a result instead of just errors.
The Sequential Machine definition itself is quite long and also
a bit convoluted. (There are quite a lot of forward/backward
references within this definition. The text would also be more
fluid to read for me if the explanation of an ijrd
list would be in this order, not irjd
.) The definition
comes with a real-life but mildly complex complex example
automaton, a tokenizer for J phrases.
I prefer to learn new things with minimalistally simple examples. This is what I started out with (around day 2):
m =. (a. {~ 97 + i. 26) ; ,'.'
s =. ,: _2 ]\ 0 0 0 6 0 6
(5;s;m) ;: 'foo.bar.baz.'
|domain error
| (5;s;m) ;:'foo.bar.baz.'
Recognizing what I had done incorrectly took me unbelievable two
or three hours. If you never used ;:
before
yourself:
Can you spot my error more quickly than I did?