I'm trying to program the sequential machine primitive ;:

However after an interminable number of attempts I am beginning to think my
problem does not have a solution.

I am trying to use ;: to extract the second sub-substring from within
substrings.
Substrings are delimited by '+' and within the substrings the sub-substrings
are delimited by ':' (the colon).
There are three states for the sm
0  and 1 correspond to + and : while 2 is any other character.

The strings will always start with a leading + .
Thus, in the example,
+a:b:c+A:B:C+
the required result is
'b';'B'

When the substrings have been elided, such as
'+++'
an acceptable result is
'+';'+'

Or in this case
'+:+:+'
an acceptable result is
':' ; ':'

Or in this case
'+123:+456:+
an acceptable result is
':' ; ':'


The following is one of my attempts:
sc=:''
sc=:sc, 3 1 0 0 0 0  NB.0
sc=:sc, 1 2 5 1 3 0  NB.1
sc=:sc, 1 2 5 2 4 2  NB.2
sc=:sc, 2 1 5 1 4 0  NB.3
sc=:sc, 2 1 5 1 4 0  NB.4
sc=:sc, 1 2 7 2 6 1  NB.5
sc=:sc, 1 2 7 2 6 0  NB.6
sc=:sc, 1 1 7 0 7 0  NB.7
sc=: 8 3 2 $sc
pp=:256$2
pp=: 0 1 (I.a.e.'+:')}pp

Here are some results that are okay...
 (0;sc;pp);:'+a:c+d:e+'
+-+-+-+
|c|e|+|
+-+-+-+
(0;sc;pp);:'+a:c+d:e+f:g+'
+-+-+-+-+
|c|e|g|+|
+-+-+-+-+

The trailing + doesnt cause a problem so long as the sm is consistent.
Which it is but only if the input string is 'well behaved'.
But when the input string degenerates so do the results.
The problem shows in the following:
(0;sc;pp);:'+:123+34+'
+---+-+
|123|+|
+---+-+
(0;sc;pp);:'+123+:34+'
+-+--+-+
|+|34|+|
+-+--+-+

I understand why the sm behaves as it does.
The question is - is it possible for it to behave the way I want?

My knowledge of finite state machines is elementary but if someone with
expertise in this area believes the problem has a solution I'll continue my
search.

Thanks
David
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to