[Newbies] Polymorphic or: with block argument

David T. Lewis lewis at mail.msen.com
Sun Sep 10 12:45:20 UTC 2017


On Sun, Sep 10, 2017 at 01:33:15PM +0200, Lorenz K??hl wrote:
> I don't understand why Smalltalk doesn't allow me to have an or:
> method that takes a block argument (except on Boolean). For example:
> 
> Set or: 1. ==> MNU as expected.
> 
> Set or: [1]. ==> NonBooleanReceiver exception.
> 
> Set or: [:x | x] ==> Argument has too many arguments
> 
> Is it because the compiler specializes this to boolean when it sees
> the or: [ ... ] syntax? Is this a tradeoff made for performance?


Hi Lorenz,

If you are looking for set operations, check these methods:

  Collection>>union:
  Collection>>intersection:
  Collection>>difference:

I am not sure what you are trying to do with your examples. Can you
explain the intent?

Dave



More information about the Beginners mailing list