fixed bug in SmallInt math primitives
[k8lst.git] / samples / yield.st
blobd6233ba1c8b05658e7035407e3c07ccd9ff350bd
1 class: Calculator [
2 | val |
4 ^newWith: aVal [
5   | obj |
6   obj := self new.
7   self in: obj var: #val put: aVal.
8   ^obj
11 run [
12   [ val > 0 ] whileTrue: [
13     System yield: val.
14     val := val - 1.
15   ].
20 class: Generator [
21 | proc |
23 ^newWith: aClass [
24   | obj ctx proc |
25   ctx := Context new.
26   ctx setup: (aClass findMethod: #run) withArguments: (Array with: aClass).
27   proc := Process new.
28   proc context: ctx.
29   obj := self new.
30   self in: obj var: #proc put: proc.
31   ^obj
34 next: aDoneBlock [
35   | res |
36   res := proc doExecute: 0.
37   res = 4 ifTrue: [ ^aDoneBlock value ].
38   res = 7 ifTrue: [ ^proc result ].
39   proc errorReport: res.
40   ^aDoneBlock value.
43 printAll [
44   | res |
45   [ true ] whileTrue: [
46     res := self next: [ 'done.' printNl. ^true ].
47     res printNl.
48   ].
53 { (Generator newWith: (Calculator newWith: 4)) printAll printNl. }