Package: Kernel-Methods
Class: BlockClosure
Introduction
Environment: container
Contains a sequence of operations
Defined by Mindscript expressions inside square brackets
Permits to defer the enclosed operations until a variant of #value is executed
Can have its own arguments and temporaries as a regular method but it also has the ability to use external variables
It has enclosing method or block temporaries, arguments, and receiver.
Some message needs a code block as argument. For example, #do:
needs a block to be executed for each element of the receiver.
The block is executed with the element as argument.
You can also use a local variable in a block:
We can also use the block as a local variable, and execute it later by sending value
to it, or value:
with an argument.
Instance Method
Category: accessing
asString
- answer the code string of this block closure.numArgs
- answer the number of arguments of the receiver.
Category: controlling
whileFalse:
- Ordinarily compiled in-line, and therefore not overridable. This is in case the message is sent to other than a literal block. Evaluate the argument, aBlock, as long as the value of the receiver is false.For example:
whileTrue:
- Ordinarily compiled in-line, and therefore not overridable. This is in case the message is sent to other than a literal block. Evaluate the argument, aBlock, as long as the value of the receiver is true.For example:
Category: evaluating
ensure:
- Evaluate a termination block after evaluating the receiver, regardless of whether the receiver's evaluation completes.onErrorDo:
- Evaluate an error handling block when there is an exception when evaluating the receiver.For example, we can use
onErrorDo:
to handle an error when divide by zero.value
- Evaluate the receiver and answer the result.value:
- Evaluate the receiver with the given argument and answer the result.value:value:
- Evaluate the receiver with the given arguments and answer the result.value:value:value:
- Evaluate the receiver with the given arguments and answer the result.value:value:value:value:
- Evaluate the receiver with the given arguments and answer the result.
Last updated