david alis wrote:
> +: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.
;: cannot produce empty words. Also, your '+++' example
did not produce empty words.
It's probably possible to do this (for example, use ev
instead of ew, change to include the first + and the
first :, then post-process with -.&'+:'&.>). But that
would mean that you'd have to accept empty word results
for '+++' and/or '+:+:+:'.
Or did you mean that there should be no word for that
element? ;: can do that rather handily, but that would
imply that '+++' would give an empty result (not a
list of three empty words).
> How do I determine whether a particular problem can
> be solved using a fsm?
I think the issue here is the one I already mentioned:
;: cannot emit empty words. There's ways around that
(it's not like you've lost the rest of J), but that's
important to understand.
> 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).
(eliminating extraneous parenthesis):
foo=: 4&{.@ (<;._1)@ (':'&,);._1@ ('+'&,)
> data=: '0:A++123.9:A:M:-+87:B+123:A:S'
This seems a reasonable approach.
And with data this small, time does not seem all that
much of an issue.
In "real life", are you processing much larger chunks
of data?
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm