Block evaluation from a collection of blocks

Jules Dubois de6l5rp02 at sneakemail.com
Mon Mar 22 05:30:13 UTC 2004


Setup: I'm trying to place a collection of blocks into
       a class variable for repeated evaluation in an
       instance method.  

In a class (FWGC) method, I create a collection of blocks which call the
class constructor, with a reference to the the collection in the class
variable 'Moves'.

    Moves == nil ifTrue:
        [Moves := OrderedCollection
            with: [:fwgc | FWGC f: fwgc f change
                                w: fwgc w
                                g: fwgc g
                                c: fwgc c]
            with: [:fwgc |
                 fwgc f = fwgc w
                      ifTrue: [FWGC f: fwgc f change
                                    w: fwgc w change
                                    g: fwgc g
                                    c: fwgc c]]
                                    
and so on.  When I try to evaluate these blocks in an FWGC instance method
using

   Moves select: [:move  | (move value: self) validate]
   
I get an error saying "This block requires 0 arguments".  Don't these
blocks take 1 argument?

As an alternative, I tried removing the ':fwgc' argument, replacing its
usage as receiver with 'self', and changing the invocation to

   Moves select: [:move | move value validate]
   
In this case, it appears the 'f:w:g:c:' message is being sent to the FWGC
class and not the fwgc instance in which the statement is bing executed.

Am I on the wrong track or is what I'm trying to do simply impossible?




More information about the Squeak-dev mailing list