Anonymous user
Execute a Markov algorithm: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments.
No edit summary |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 3,023:
Code was added to the REXX example to optionally list the contents of the ruleset and/or the Markov entries.
<br>Also, blank lines in the ruleset were treated as comments.
<lang rexx>/*REXX
parse arg low high . /*
if low=='' | low==',' then low=1 /*
if high=='' | high==',' then high=6 /*
tellE
call readEntry
do j=abs(low) to abs(high) /*process each of these rulesets. */
call readRules j /*read a particular ruleset. */
call execRules j /*execute " " " */
say 'result for ruleset' j"≡"!.j
end /*j*/
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
execRules: parse arg q .;
do f=1
do k=1 while @.k\==''; if left(@.k,1)=='#' | @.k='' then iterate
parse var @.k a ' ->' b; a=strip(a); b=strip(b)
fullstop= left(b,1)=='.' /*is this a "fullstop" rule? */
if fullstop then b=substr(b,2) /*purify the B part of the rule. */
old=!.q /*remember the value before the change.
!.q=changestr(a, !.q, b) /*implement the ruleset change. */
if fullstop then if old\==!.q then return /*should we stop? */
if old\==!.q then iterate f /*Has Entry changed? Then start over.*/
end /*k*/
leave
end /*f*/
return
/*────────────────────────────────────────────────────────────────────────────*/
readRules: parse arg ? .; rFID='MARKOV_R.'?; if tellR then say
@.= /*placeholder
do r=1 while lines(rFID)\==0 /*read the input file until
@.r=linein(rFID); if tellR then say 'ruleSet' ?"."left(r,4)'≡'@.r
end /*r*/ /*(above) read and maybe echo
return
/*────────────────────────────────────────────────────────────────────────────*/
readEntry:
!.= /*placeholder
do e=1 while lines(eFID)\==0 /*read the input file until
!.e=linein(eFID); if tellE then say 'test entry' e"≡"!.e
end /*e*/ /*(above) read and maybe echo
return</lang>
Some older REXXes don't have a '''changestr'''
<br><br>
'''output''' when using the default input and files:
<pre>
result for ruleset 1≡I bought a bag of apples from my brother.
|