Login  Register

Re: How does Boolean ifTrue work?

Posted by Thierry Goubier on Oct 31, 2016; 2:17pm
URL: https://forum.world.st/How-does-Boolean-ifTrue-work-tp4920873p4920888.html

Le 31/10/2016 à 14:58, CodeDmitry a écrit :
> But still, how is the actual argument "alternativeBlock" passed to the
> True/False from a Boolean?
>
> The message does not cache the message inside itself before passing the
> message, and it does not pass the alternative block along with the message.

If I get correctly what you are saying, this is because the
ifTrue:ifFalse: message is never sent to an instance of Boolean.

It is sent either to true, the single instance of class True, or to
false, the single instance of class False, where the implementation is
what you expect:

False>>#ifTrue:ifFalse:

ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
        "Answer the value of falseAlternativeBlock. Execution does not
        actually reach here because the expression is compiled in-line."

        ^falseAlternativeBlock value

If you're interested in the details, do also read the comment.

Regards,

Thierry