Predicates¶
Fives¶
"GoalTest, protocol tests"
testFives
| g |
g := [ :x | self fives: x ] asGoal.
self
assert: (g solutions next: 10)
equals: { 5. 5. 5. 5. 5. 5. 5. 5. 5. 5 }
modulo: #asOrderedCollection.
^ self exportComputationTreeOfGoal: g limitedTo: 10
where
"GoalTest, protocol utilities" fives: x ^ (5 unifyo value: x) | [ self fives: x ] asGoal
"GoalTest, protocol tests"
testFivesByPredicate
| g |
g := [ :r | MKPredicateFives value: r ] asGoal.
self
assert: (g solutions next: 10)
equals: { 5. 5. 5. 5. 5. 5. 5. 5. 5. 5 }
modulo: #asOrderedCollection.
^ self exportComputationTreeOfGoal: g limitedTo: 10
Nats¶
"GoalTest, protocol tests"
testNats
| g M |
M := 1000.
g := [ :x | self nats: x ] asGoal.
self
assert: (g solutions next: M)
equals: (0 to: M - 1)
modulo: #asOrderedCollection.
^ self exportComputationTreeOfGoal: g limitedTo: 10
where
"GoalTest, protocol utilities" nats: x ^ self nats: x stage: 0"GoalTest, protocol utilities" nats: x stage: i ^ self nats: x stage: i offset: 1"GoalTest, protocol utilities" nats: x stage: i offset: o ^ (x unifyo value: i) | [ self nats: x stage: i + o offset: o ] asGoal
Indeed, the enumeration of 5s can also be achieved with:
"GoalTest, protocol tests"
testFivesByNats
| g |
g := [ :x | self repeat: x value: 5 ] asGoal.
self
assert: (g solutions next: 10)
equals: { 5. 5. 5. 5. 5. 5. 5. 5. 5. 5 }
modulo: #asOrderedCollection.
^ self exportComputationTreeOfGoal: g limitedTo: 10
where
"GoalTest, protocol accessing structure variables" repeat: x value: i ^ self nats: x stage: i offset: 0