From 2479b94b677ea508a603ef208f14cad35b681a1d Mon Sep 17 00:00:00 2001 From: Micah Kendall Date: Sat, 26 Nov 2022 23:48:08 +1100 Subject: [PATCH] More boolean examples, similar to gleam book. Also, explain correspondence to plutus primitives. --- book/src/language-tour/bool.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/book/src/language-tour/bool.md b/book/src/language-tour/bool.md index 5a3e892a..f030905f 100644 --- a/book/src/language-tour/bool.md +++ b/book/src/language-tour/bool.md @@ -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 } ``` \ No newline at end of file