#and:, #or: methods in blocks?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

#and:, #or: methods in blocks?

Petr Fischer-3
Hi,

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 ]

Thanks for clarification, pf
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: #and:, #or: methods in blocks?

Bert Freudenberg

On Apr 10, 2007, at 23:40 , Petr Fischer wrote:

> Hi,
>
> 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 -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners