Applying this sm to your last two examples
+:123+34+
+123+:34+
doesnt provide the result needed..

+:123+34+ should produce two elements - the first being 123 while the
second should be empty. Instead the sm puts '4' into the second
element.

+123+:34+ should also have two elements, the first being empty - but
this time the sm puts '3' into the first element.

How do I determine whether a particular problem can be solved using a fsm?

In my actual application I use the verb 'foo' on strings such as
'data' (the application specifies there is a maximum of 4 elements
within each part).

foo =: ((((4&{.)@(<;._1)@(':'&,)));._1)@('+'&,)
data=: '0:A++123.9:A:M:-+87:B+123:A:S'

foo data
+-----+-+-+-+
|0    |A| | |
+-----+-+-+-+
|     | | | |
+-----+-+-+-+
|123.9|A|M|-|
+-----+-+-+-+
|87   |B| | |
+-----+-+-+-+
|123  |A|S| |
+-----+-+-+-+
from which I can extract the pieces I need.

Using ;:  is at least 10 times quicker than using cut (;.) - because
of the need to apply ;. explicitly within each substring. But because
I rely on ;: to always produce the correct result.

Thanks for your efforts.
Regards
David


Raul Miller wrote: <Mon Jan 22 11:56:55 HKT 2007>
....

NB. +    :        NB. each entry is nextState.outputCode
sc=:0 10#:10*".;._2(0 :0)
 1.1  1.1  1.1   NB. 0 initial state
 1.2  2.1  1.1   NB. 1 got '+', waiting for first ':'
 1.2  3.3  4.1   NB. 2 got '+:', handle next char
 1.1  3.0  3.0   NB. 3 got '+::', waiting for next '+'
 1.2  3.3  4.0   NB. 4 got '+:x' waiting for + or :
)
pp=: '+:'i.a.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to