| as yet unclassified |
| callcc: aBlock
|
^ Continuation currentDo: aBlock
|
| testBlockEscape
|
|x|
tmp _ 0.
x _ [tmp _ tmp + 1. tmp2 value].
self callcc: [:cc | tmp2 _ cc. x value].
tmp2 _ [].
x value.
self assert: tmp = 2.
|
| testBlockTemps
|
|y|
#(1 2 3) do:
[:i ||x|
x _ i.
tmp ifNil: [tmp2 _ (self callcc: [:cc | tmp _ cc. [:q]])].
tmp2 value: x.
x _ 17].
y _ (self callcc: [:cc | tmp value: cc. 42]).
self assert: y = 1.
|
| testBlockVars
|
|continuation|
tmp _ 0.
tmp _ (self callcc: [:cc | continuation _ cc. 0]) + tmp.
tmp2
ifNotNil: [tmp2 value]
ifNil:
[#(1 2 3) do:
[:i |
self callcc: [:cc | tmp2 _ cc. continuation value: i]]].
self assert: tmp = 6.
|
| testComprehension
|
"What should this print out?
|yin yang|
yin := [:x | Transcript cr. x] value: Continuation current.
yang := [:x | Transcript nextPut: $*. x] value: Continuation current.
yin value: yang."
|
| testMethodTemps
|
|i continuation|
i _ 0.
i _ i + (self callcc: [:cc | continuation _ cc. 1]).
self assert: i ~= 3.
i = 2 ifFalse: [continuation value: 2].
|
| testSimpleCallCC
|
|x continuation|
x _ self callcc: [:cc | continuation _ cc. false].
x ifFalse: [continuation value: true].
self assert: x.
|
| testSimplestCallCC
|
|x|
x _ self callcc: [:cc | cc value: true].
self assert: x.
|