# Lab 6 - Gleamified [](https://hex.pm/packages/bible_search) [](https://hexdocs.pm/bible_search/) ```gleam pub fn bible_scan( reference reference: Reference, bible bible: String, ) -> ScanResult { let inital_state = ScanState( phase: Book, ref: reference, found_book: False, found_chapter: False, verse_text: Error("Verse not found"), ) let bible_lines = string.split(bible, "\n") let result = list.fold(bible_lines, inital_state, fn(state, line) -> ScanState { case state.phase { Done -> state Book -> case line { "THE BOOK OF " <> book -> case book == state.ref.book { True -> ScanState(..state, phase: Chapter, found_book: True) False -> state } _ -> state } Chapter -> case line { "CHAPTER " <> chapter -> case result.unwrap(int.parse(chapter), 0) == state.ref.chapter { True -> ScanState(..state, phase: Verse, found_chapter: True) False -> state } _ -> state } Verse -> fn() { let parts = string.split(line, " ") case parts { [first, ..rest] -> case result.unwrap(int.parse(first), 0) == state.ref.verse { True -> ScanState( ..state, phase: Done, verse_text: Ok(string.join(rest, " ")), ) False -> state } _ -> state } }() } }) ScanResult(ref: reference, verse: result.verse_text) } ``` For this lab the program must parse `OT.txt` (format below) to find specific references and produce scoped errors if the reference isn't found. ```text THE BOOK OF GENESIS CHAPTER 1 1 In the beginning God created the heaven and the earth. 2 And the earth was without form, and void; and darkness [was] upon the face of the deep. And the Spirit of God moved upon the face of the waters. 3 And God said, Let there be light: and there was light. 4 And God saw the light, that [it was] good: and God divided the light from the darkness. THE BOOK OF PSALMS PSALM 1 1 Blessed [is] the man that walketh not in the counsel of the ungodly, nor standeth in the way of sinners, nor sitteth in the seat of the scornful. 2 But his delight [is] in the law of the LORD; and in his law doth he meditate day and night. 3 And he shall be like a tree planted by the rivers of water, that bringeth forth his fruit in his season; his leaf also shall not wither; and whatsoever he doeth shall prosper. ``` ## Development You need to have the [gleam runtime](https://gleam.run/getting-started/installing/) installed as well as erlang for the beam runtime. ```sh gleam run gleam test # runs all the test functions in /tests postfixed with _test ```
© 2025-present Kieran Klukas