eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Lazy':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Lazy


Inheritance:

   ProtoObject
   |
   +--Lazy

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.14 date: 2018/02/01 22:42:59
user: stefan
file: Lazy.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
tph@cs.man.ac.uk

Description:


I represent an execution which may or may not be required.
I will not start execution until at least one message has been received.
The messages sent to me are delayed until execution has completed.


Related information:

    Block
    LazyValue
    Future

Instance protocol:

evaluating
o  block: aBlock
Execute aBlock in parallel, but ensure that any messages sent
to me before execution of the block has terminated are
suspended until it has terminated. Do not start the evaluation
until at least one message has been sent to the receiver.

o  block: aBlock value: aValue
Execute aBlock in parallel, but ensure that any messages sent
to me before execution of the block has terminated are
suspended until it has terminated. Do not start the evaluation
until at least one message has been sent to the receiver.

o  block: aBlock value: value1 value: value2
Execute aBlock in parallel, but ensure that any messages sent
to me before execution of the block has terminated are
suspended until it has terminated. Do not start the evaluation
until at least one message has been sent to the receiver.

o  block: aBlock value: value1 value: value2 value: value3
Execute aBlock in parallel, but ensure that any messages sent
to me before execution of the block has terminated are
suspended until it has terminated. Do not start the evaluation
until at least one message has been sent to the receiver.

o  block: aBlock valueWithArguments: anArray
Execute aBlock in parallel, but ensure that any messages sent
to me before execution of the block has terminated are
suspended until it has terminated. Do not start the evaluation
until at least one message has been sent to the receiver.

printing
o  displayOn: aGCOrStream
what a kludge - Dolphin and Squeak mean: printOn: a stream;

o  displayString
attention: TextStream is not present in ultra-mini standalone apps

synchronising
o  _evaluate_
answer the computed value

o  doesNotUnderstand: aMessage
Any message to a Lazy will end up here.

o  perform: aSelector withArguments: argArray
send the message aSelector with all args taken from argArray
to the receiver.

testing
o  isLazyValue


Examples:


Evaluates the factorial, starting only when the result is actually required (when printString is sent).
  | fac |
  fac := [100 factorial] lazyValue.
  Transcript showCR: 'Doing nothing. '.
  (Delay forSeconds: 2) wait.
  Transcript showCR: fac printString.
Starts evaluating both factorials only when required (by the value), and waits until both blocks have finished before continuing.
  | fac1 fac2 |
  fac1 := [Transcript showCR: 'Starting fac1.. '. 100 factorial] lazyValue.
  fac2 := [Transcript showCR: 'Starting fac2.. '. 120 factorial] lazyValue.
  fac2 value.
  fac1 value.
  Transcript showCR: 'both completed.'.
Demonstrates how to pass arguments to a lazy evaluation block.
  | temp |
  temp := [:x :y :z | x * y * z] lazyValueWithArguments: #(2 3 4).
  Transcript  showCR: temp printString.


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 16 Dec 2018 22:13:08 GMT