Anonymous user
Execute a Markov algorithm: Difference between revisions
→{{header|Tcl}}: Make the code more compact
(→{{header|J}}: minor imrovement (due to nsg & vc)) |
(→{{header|Tcl}}: Make the code more compact) |
||
Line 427:
if {[string match "#*" $line] || $line eq ""} continue
if {[regexp {^(.+)\s+->\s+(\.?)(.*)$} $line -> from final to]} {
lappend rules $from $to [string
} else {
error "Syntax error: \"$line\""
Line 440:
while {$any} {
set any 0
foreach {from to
# If we match the 'from' pattern...
if {[set idx [string first $from $line]]
▲ # Change for the 'to' replacement
▲ set line [string replace $line $idx [expr {$idx+$fl-1}] $to]
break; # Restart search for rules to apply
▲ set any 0
}
}
#DEBUG# puts $line
}
|