Amb: Difference between revisions

Content deleted Content added
→‎{{header|Tcl}}: Added a coroutine-based version
m →‎{{header|Tcl}}: formatting
Line 414: Line 414:
=={{header|Tcl}}==
=={{header|Tcl}}==
Brute force, with quick kill of failing attempts:
Brute force, with quick kill of failing attempts:
<lang Tcl>
<lang Tcl>set amb {
set amb {
{the that a}
{the that a}
{frog elephant thing}
{frog elephant thing}
Line 439: Line 438:
}
}
}</lang>
}</lang>

A more sophisticated using Tcl 8.6's coroutine facility that avoids the assumption of what the problem is in the code structure:
A more sophisticated using Tcl 8.6's coroutine facility that avoids the assumption of what the problem is in the code structure:
<lang Tcl>
<lang Tcl>proc cp {args} {
proc cp {args} {
coroutine cp.[incr ::cps] apply {{list args} {
coroutine cp.[incr ::cps] apply {{list args} {
yield [info coroutine]
yield [info coroutine]
Line 481: Line 478:
{walked treaded grows} \
{walked treaded grows} \
{slowly quickly}
{slowly quickly}
while 1 { puts [words] }
while 1 { puts [words] }</lang>
</lang>