Chapter 1: First steps
Pac-Man rules
- Bool
- and / or / not
- imports
Bea spells boolean logic as words: and, or and
not. They become Gleam's &&,
|| and !, and they short-circuit the same way.
import gleam/io brings in the standard library's IO module.
You can skip imports for the standard library entirely: Bea adds
list, string, int and friends
automatically when you use them.
import gleam/io
def eat_ghost(power_pellet_active: Bool, touching_ghost: Bool) -> Bool {
touching_ghost and power_pellet_active
}
def score(touching_power_pellet: Bool, touching_ghost: Bool) -> Bool {
touching_ghost or touching_power_pellet
}
def lose(power_pellet_active: Bool, touching_ghost) -> Bool {
touching_ghost and not power_pellet_active
}
pub def main() {
echo eat_ghost(True, False)
echo score(False, True)
echo lose(True, True)
io.println("Done!")
}import gleam/io
fn eat_ghost(power_pellet_active: Bool, touching_ghost: Bool) -> Bool {
touching_ghost && power_pellet_active
}
fn score(touching_power_pellet: Bool, touching_ghost: Bool) -> Bool {
touching_ghost || touching_power_pellet
}
fn lose(power_pellet_active: Bool, touching_ghost) -> Bool {
touching_ghost && !power_pellet_active
}
pub fn main() {
echo eat_ghost(True, False)
echo score(False, True)
echo lose(True, True)
io.println("Done!")
}src/e3_pacman_rules.bea:16
False
src/e3_pacman_rules.bea:17
True
src/e3_pacman_rules.bea:18
False
Done!An exercism exercise from the Gleam track, solved in Bea: beacode/src/e3_pacman_rules.bea