[Newbies] #and:, #or: methods in blocks?
bert at freudenbergs.de
Tue Apr 10 21:55:09 UTC 2007
On Apr 10, 2007, at 23:40 , Petr Fischer wrote:
> methods #and:, #or: etc. are defined in Boolean class only - why
> this methods are not defined in "blocks" too?
> * standard way (brackets mix):
> ( condition_1 ) and: [ condition_2 ] ...
> * this (fictive) way looks beter (for me):
> [ condition_1 ] and: [ condition_2 ] ...
> more complex one: [ [ cond_1 ] and: [ cond_2 ] ] or: [ cond_3 ]
You only need blocks for code that is evaluated conditionally, or
repeatedly, or not immediately.
But the receiver of #and: or #or: always must be evaluated. No sense
in making it a block. In contrast, the argument to #and: must only be
evaluated if the receiver was true. So you need a block there.
If you do not need that shortcut behavior you can simply use #& and
#| which take booleans, not blocks as arguments.
- Bert -
More information about the Beginners