harlowe:boolean

# Differences

This shows you the differences between two versions of the page.

 harlowe:boolean [2017/06/19 02:17]l harlowe:boolean [2017/10/09 20:39] Line 1: Line 1: - Computers can perform more than just mathematical tasks - they are also virtuosos in classical logic. Much as how - arithmetic involves manipulating [[harlowe:​number|number]] with addition, multiplication and such, logic involves manipulating the - values ''​%%true%%''​ and ''​%%false%%''​ using its own operators. Those are not text [[harlowe:​string|string]] - they are values as fundamental as - the natural numbers. In computer science, they are both called //​Booleans//,​ after the 19th century mathematician - George Boole. - ''​%%is%%''​ is a logical operator. Just as + adds the two numbers on each side of it, ''​%%is%%''​ compares two values on each - side and evaluates to ''​%%true%%''​ or ''​%%false%%''​ depending on whether they'​re identical. It works equally well with strings, - numbers, [[harlowe:​Array|Array]],​ and anything else, but beware - the string ''​%%"​2"​%%''​ is not equal to the number 2. - - There are several other logical operators available. - ^Operator ​       ^ Purpose ^ Example ^ - | ''​%%is%%''​ | Evaluates to ''​%%true%%''​ if both sides are equal, otherwise ''​%%false%%''​. | ''​%%\$bullets is 5%%''​ - | ''​%%is not%%''​ | Evaluates to ''​%%true%%''​ if both sides are not equal. | ''​%%\$friends is not \$enemies%%''​ - | ''​%%contains%%''​ | Evaluates to ''​%%true%%''​ if the left side contains the right side. | ''​%%"​Fear"​ contains "​ear"​%%''​ - | ''​%%is in%%''​ | Evaluates to ''​%%true%%''​ if the right side contains the left side. | ''​%%"​ugh"​ is in "​Through"​%%''​ - | ''​%%>​%%''​ | Evaluates to ''​%%true%%''​ if the left side is greater than the right side. | ''​%%\$money > 3.75%%''​ - | ''​%%>​=%%''​ | Evaluates to ''​%%true%%''​ if the left side is greater than or equal to the right side. | ''​%%\$apples >= \$carrots + 5%%''​ - | ''​%%<​%%''​ | Evaluates to ''​%%true%%''​ if the left side is less than the right side. | ''​%%\$shoes < \$people * 2%%''​ - | ''​%%<​=%%''​ | Evaluates to ''​%%true%%''​ if the left side is less than or equal to the right side. | ''​%%65 <= \$age%%''​ - | ''​%%and%%''​ | Evaluates to ''​%%true%%''​ if both sides evaluates to ''​%%true%%''​. | ''​%%\$hasFriends and \$hasFamily%%''​ - | ''​%%or%%''​ | Evaluates to ''​%%true%%''​ if either side is ''​%%true%%''​. | ''​%%\$fruit or \$vegetable%%''​ - | ''​%%not%%''​ | Flips a ''​%%true%%''​ value to a ''​%%false%%''​ value, and vice versa. | ''​%%not \$stabbed%%''​ - - - Conditions can quickly become complicated. The best way to keep things straight is to use parentheses to - group things.