Squeak programming question

ohshima at is.titech.ac.jp ohshima at is.titech.ac.jp
Mon Mar 22 13:17:40 UTC 1999


  Hi,

> Is there any elegant method for handling occasions when you
> wish a method to return multiple objects?  I'm writing a
> method that will return a set and a dictionary to the
> caller.  I can't reasonably break up the method into two
> methods (one for each kind of data), and the contents of
> the set and dictionary are unrelated enough that it seems
> silly to make a whole new class of object containing nothing
> but pointers to each.  The only thing that occurs to me is
> something like:
>  
> ^((OrderedCollection new) add: myDictionary add: mySet)
> 
> and then disassemble the thing on the receiving side.  I'm
> not really crazy about this though.

  One possibility is something like a continuation passing
style programming.  Namely, your method gets extra argument
which is a two-argument block, and the method calls the
block at the end:

  yourMethod: anArgument whatToDoNext: aBlock

      ...
      aBlock value: myDictionary value: mySet.

  In this way, myDictionary and mySet can be used in the
block without creating the instance of OrderedCollection.

  Or, if the problem is syntax, you may want to use the
brace array constructor:

    ^{myDictionary . mySet}

  This is equivalent to

    ^Array with: myDictionary with: mySet

                                             OHSHIMA Yoshiki
                Dept. of Mathematical and Computing Sciences
                               Tokyo Institute of Technology 





More information about the Squeak-dev mailing list