Part 3: the language


What can it do? - Blocks

classic Smalltalk-80 blocks:
  • non-reentrant; cannot write:

    |b|
    b := [:x | (x < 2)
                       ifTrue:   [1]
                       ifFalse: [ x * (b value: x -1) ] ].
    ^b value: 5
  • arguments shared with method; can write:

    frobAndSetClass: setBlock
        "frobs and sets the class"
          self frob.
          setBlock value: self class


    code to test this:

    |aClass|
    someObject frobAndSetClass: [:aClass].
    Transcript show: aClass name