Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
85
Task/Amb/Elena/amb.elena
Normal file
85
Task/Amb/Elena/amb.elena
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import system'routines;
|
||||
import extensions;
|
||||
import extensions'routines;
|
||||
|
||||
joinable(former,later) = (former[former.Length - 1] == later[0]);
|
||||
|
||||
dispatcher = new
|
||||
{
|
||||
eval(object a, Func2 f)
|
||||
{
|
||||
^ f(a[0],a[1])
|
||||
}
|
||||
|
||||
eval(object a, Func3 f)
|
||||
{
|
||||
^ f(a[0], a[1],a[2])
|
||||
}
|
||||
|
||||
eval(object a, Func4 f)
|
||||
{
|
||||
^ f(a[0],a[1],a[2],a[3])
|
||||
}
|
||||
|
||||
eval(object a, Func5 f)
|
||||
{
|
||||
^ f(a[0],a[1],a[2],a[3],a[4])
|
||||
}
|
||||
};
|
||||
|
||||
class AmbValueCollection
|
||||
{
|
||||
object theCombinator;
|
||||
|
||||
constructor new(params object[] args)
|
||||
{
|
||||
theCombinator := SequentialEnumerator.new(params args)
|
||||
}
|
||||
|
||||
seek(cond)
|
||||
{
|
||||
theCombinator.reset();
|
||||
|
||||
theCombinator.seekEach:(v => dispatcher.eval(v,cond))
|
||||
}
|
||||
|
||||
do(f)
|
||||
{
|
||||
var result := theCombinator.get();
|
||||
if (nil != result)
|
||||
{
|
||||
dispatcher.eval(result,f)
|
||||
}
|
||||
else
|
||||
{
|
||||
InvalidArgumentException.raise()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
singleton ambOperator
|
||||
{
|
||||
for(params object[] args)
|
||||
= AmbValueCollection.new(params args);
|
||||
}
|
||||
|
||||
public program()
|
||||
{
|
||||
try
|
||||
{
|
||||
ambOperator
|
||||
.for(
|
||||
new object[]{"the","that","a"},
|
||||
new object[]{"frog", "elephant", "thing"},
|
||||
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"
|
||||
};
|
||||
|
||||
console.readChar()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue