On Wed, Jan 13, 2010 at 1:52 PM, Dan Bron <[email protected]> wrote:
> [1] Poxy tacit version and healthy explicit version of a Markov engine:
> http://rosettacode.org/wiki/Talk:Markov_Algorithm#explicit_vs_tacit
First off, I have long felt that tacit is a tool which should not be
overused.
That said, I think the markov implementation could benefit from
something like this:
require 'regex'
firstMatch=: ({~ (i. <./)@:({...@i.@:(*...@{:"1)@}."2))@rxmatches
For example, the rules
baa->def
a->b
could be used to build the regular expression:
'(baa)|(a)'
and
'(baa)|(a)' firstMatch 'aaa'
0 1
_1 0
0 1
The first character of this string matches the second rule
'(baa)|(a)' firstMatch 'baa'
The first three characters of this string matches the first rule
If rules contained non-alphanumeric characters they would
need to have those characters escaped when building the
regular expression. I have not studied the rosetta spec to
know if this would ever be an issue.
Also some of the code that I dumped into firstMatch would
also need to be used to recognize which of the rules was
being matched. I am just trying to illustrate an approach here,
I am not trying to actually solve the problem.
But, in principle, this approach could be used to deal with
that problem.
FYI,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm