More boolean examples, similar to gleam book. Also, explain correspondence to plutus primitives.

This commit is contained in:
Micah Kendall 2022-11-26 23:48:08 +11:00 committed by Lucas
parent 9b3c8e432e
commit 2479b94b67
1 changed files with 26 additions and 6 deletions

View File

@ -1,19 +1,39 @@
# Bool
Bools are True or False
There are logical conjunctions (True && True) or disjunctions (True || False).
Bools (short for booleans) are True or False. They correspond to the plutus bool primitive type.
There are logical disjunctions (True || False) or conjunctions (True && True).
```gleam
fn negate(b: Bool)->Bool {
False || False -- -> False
True || False -- -> True
False || True -- -> True
True || True -- -> True
False && False -- -> False
True && False -- -> False
False && True -- -> False
True && True -- -> True
```
These are implemented using the plutus ifThenElse primitive.
```gleam
a || b -- if a {True} else {b} -- ifThenElse(a, True, b)
a && b -- if a {b} else {False} -- ifThenElse(a, b, False)
```
An if statement decides on a boolean value.
```gleam
fn negate(b: Bool) -> Bool {
if b {
False
}else{
True
}
}
```
fn and(b: Bool, c: Bool, d: Bool)->Bool{
The && operator in a function
```gleam
fn and(b: Bool, c: Bool, d: Bool) -> Bool{
b && c && d
}
```