Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
125
Task/Amb/Elena/amb.elena
Normal file
125
Task/Amb/Elena/amb.elena
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#define system.
|
||||
#define extensions.
|
||||
#define extensions'routines.
|
||||
|
||||
// --- Joinable --
|
||||
|
||||
#symbol joinable = (:aFormer:aLater)
|
||||
[ (aFormer @ (aFormer length - 1)) == (aLater @ 0) ].
|
||||
|
||||
// --- Activatora ---
|
||||
|
||||
#class(role)Activator2
|
||||
{
|
||||
#method eval : anArray
|
||||
[
|
||||
^ self eval:(anArray@0):(anArray@1).
|
||||
]
|
||||
}
|
||||
|
||||
#class(role)Activator3
|
||||
{
|
||||
#method eval : anArray
|
||||
[
|
||||
^ self eval:(anArray@0):(anArray@1):(anArray@2).
|
||||
]
|
||||
}
|
||||
|
||||
#class(role)Activator4
|
||||
{
|
||||
#method eval : anArray
|
||||
[
|
||||
^ self eval:(anArray@0):(anArray@1):(anArray@2):(anArray@3).
|
||||
]
|
||||
}
|
||||
|
||||
#class(role)Activator5
|
||||
{
|
||||
#method eval : anArray
|
||||
[
|
||||
^ self eval:(anArray@0):(anArray@1):(anArray@2):(anArray@3):(anArray@4).
|
||||
]
|
||||
}
|
||||
|
||||
// --- AmbValueCollection ---
|
||||
|
||||
#class AmbValueCollection
|
||||
{
|
||||
#field theCombinator.
|
||||
#field theRole.
|
||||
|
||||
#constructor new : aSet1 : aSet2
|
||||
[
|
||||
theRole := Activator2.
|
||||
theCombinator := CombinatorWithRepetition new:(aSet1,aSet2).
|
||||
]
|
||||
|
||||
#constructor new : aSet1 : aSet2 : aSet3
|
||||
[
|
||||
theRole := Activator3.
|
||||
theCombinator := CombinatorWithRepetition new:(aSet1,aSet2,aSet3).
|
||||
]
|
||||
|
||||
#constructor new : aSet1 : aSet2 : aSet3 : aSet4
|
||||
[
|
||||
theRole := Activator4.
|
||||
theCombinator := CombinatorWithRepetition new:(aSet1,aSet2,aSet3,aSet4).
|
||||
]
|
||||
|
||||
#constructor new : aSet1 : aSet2 : aSet3 : aSet4 : aSet5
|
||||
[
|
||||
theRole := Activator5.
|
||||
theCombinator := CombinatorWithRepetition new:(aSet1,aSet2,aSet3,aSet4,aSet5).
|
||||
]
|
||||
|
||||
#method seek : aCondition
|
||||
[
|
||||
theCombinator reset.
|
||||
|
||||
control while:[ theCombinator next ] &do:
|
||||
[
|
||||
aCondition~theRole eval:(theCombinator get) ?
|
||||
[ #break nil. ].
|
||||
].
|
||||
]
|
||||
|
||||
#method do : aFunction
|
||||
[
|
||||
#var aResult := theCombinator get.
|
||||
nil != aResult
|
||||
? [ aFunction~theRole eval:aResult. ]
|
||||
! [ #throw InvalidArgumentException new. ].
|
||||
]
|
||||
}
|
||||
|
||||
// --- ambOperator ---
|
||||
|
||||
#symbol ambOperator =
|
||||
{
|
||||
for : aSet1 : aSet2
|
||||
= AmbValueCollection new:aSet1:aSet2.
|
||||
|
||||
for : aSet1 : aSet2 : aSet3
|
||||
= AmbValueCollection new:aSet1:aSet2:aSet3.
|
||||
|
||||
for : aSet1 : aSet2 : aSet3 : aSet4
|
||||
= AmbValueCollection new:aSet1:aSet2:aSet3:aSet4.
|
||||
|
||||
for : aSet1 : aSet2 : aSet3 : aSet4 : aSet5
|
||||
= AmbValueCollection new:aSet1:aSet2:aSet3:aSet4:aSet5.
|
||||
}.
|
||||
|
||||
// --- Program ---
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
ambOperator for:(1,2,4):(4,5,6) seek: (:a:b) [ a * b == 8 ] do: (:a:b)
|
||||
[ consoleEx writeLine: a : " * " : b : " = 8" ]
|
||||
| if &InvalidArgumentError: e [ consoleEx writeLine:"AMB is angry". ].
|
||||
|
||||
ambOperator
|
||||
for:("the","that","a"):("frog", "elephant", "thing"):("walked", "treaded", "grows"):("slowly", "quickly")
|
||||
seek: (:a:b:c:d) [ (joinable:a:b) and:(joinable:b:c) and:(joinable:c:d) ]
|
||||
do: (:a:b:c:d) [ consoleEx writeLine:a:" ":b:" ":c:" ":d. ]
|
||||
| if &InvalidArgumentError: e [ consoleEx writeLine:"AMB is angry". ].
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue