December 22, 2024

Answer to Booleans Q2

 

(a)
true

Explanation

aToad position - 10 == aFrog position | (aToad colour = aFrog colour )

this leads to

aToad position - 10 == aFrog position | (Brown = Green)

which evaluates to

aToad position - 10 == aFrog position | false

which evaluates to

11 - 10 == 1 | false

which evaluates to

1 == 1 | false

which evaluates to

true | false

which answers true

(b)
false

Explanation

aToad position - 10 == aFrog position | aToad colour = aFrog colour

Evaluating left to right and evaluating unary messages first leads to
11 - 10 == 1 | Brown = Green
This gives us four binary messages that will be evaluated from left to right giving
1 == 1 | Brown = Green giving
true | Brown = Green
true | Brown returns true. Even if the argument is not a Boolean, in this case the argument is Brown, sending the message | Brown to true will answer true. This evaluates to
true = Green which returns false
This all goes to show how important those parentheses are.

(c)
false

Explanation

(aToad position - 10 == aFrog position) not  & (aToad colour = aFrog colour) not

evaluates to

(11 - 10 == 1)not & ( Brown = Green) not

evaluates to

(1 == 1)not & ( false)not

evaluates to

true not & false not

evaluates to

false & true

which answers
false

 

Back to « Basic Questions on Booleans

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page