I am trying to create a method for the existing BlockClosure class. This is a method we wrote on the board in class, but it is not behaving exactly as I'd want it to. This is the code:
BlockClosure extend[
times: count[
count = 0
ifTrue:
[^self value.]
ifFalse:
[self value. self times: count - 1.].
]
].
I tried testing it out by inputting this into the gst interpreter:
st> x:= 5
5
st> y := [x-1] times: 4.
a BlockClosure
But I want y to equal 1 in this case. Why is y's value becoming "a BlockClosure"?
EDIT: The correct times method.
BlockClosure extend[
times: count[
count = 0
ifFalse:
[self value. ^self times: count - 1.].
]
].