Amb: Difference between revisions

75 bytes removed ,  18 days ago
m (Minor error correction.)
(5 intermediate revisions by 4 users not shown)
Line 1,454:
constructor new(params object[] args)
{
_combinator := SequentialEnumerator.newload(params args)
}
 
Line 1,461:
_combinator.reset();
 
_combinator.seekEach::(v => dispatcher.eval(v,cond))
}
Line 1,498:
new object[]{"walked", "treaded", "grows"},
new object[]{"slowly", "quickly"})
.seek::(a,b,c,d => joinable(a,b) && joinable(b,c) && joinable(c,d) )
.do::(a,b,c,d) { console.printLine(a," ",b," ",c," ",d) }
}
catch(Exception e)
{
console.printLine:("AMB is angry")
};
Line 2,448:
 
=={{header|langur}}==
{{works with|langur|0.11}}
This would build every valid set, but for the sample data, there's only one.
 
<syntaxhighlight lang="langur">val .wordsets = [
wfw/the that a/,
wfw/frog elephant thing/,
wfw/walked treaded grows/,
wfw/slowly quickly/,
]
 
val .alljoin = ffn(.words) { for[=true] .i of len(.words)-1 {
if last(.words[.i]) != first(.words[.i+1]): break = false
}}
 
# .amb expects 2 or more arguments
val .amb = ffn(...[2 .. -1] .words) { if(.alljoin(.words): join " ", .words) }
 
writeln join "\n", filter( mapX( .amb, .wordsets...))</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
Line 5,288:
uBasic/4tH has limited support for arrays, so some workarounds are required to make this work.
<syntaxhighlight lang="text"> ' set up the arrays
Push Dup("the"), Dup("that"), Dup("a") : a = FUNC(_Ambsel (0))
Push Dup("frog"), Dup("elephant"), Dup("thing") : b = FUNC(_Ambsel (a))
Push Dup("walked"), Dup("treaded"), Dup("grows") : c = FUNC(_Ambsel (b))
Push Dup("slowly"), Dup("quickly") : f = FUNC(_Ambsel (c))
' we'll reuse variable f ;-)
Proc _Ambassert (_Connect) ' now assert the function required
Line 5,327:
0 OK, 0:772
</pre>
 
=={{header|VBScript}}==
=====Implementation=====
Line 5,407 ⟶ 5,408:
{{trans|Go}}
Based on the 'alternative' version.
<syntaxhighlight lang="ecmascriptwren">var finalRes = []
 
var amb // recursive closure
885

edits