Skip to content

Commit 4e8542f

Browse files
committed
test(chapter3): improve fetch function examples
Replace commented-out evaluations with proper #guard_msgs tests, add example using list indexing syntax, and improve formatting. The changes: - Format the fetch function pattern match for better alignment - Replace commented #eval with proper Lean 4 #guard_msgs test annotations - Add a second test demonstrating the [2]? indexing syntax as an alternative to fetch
1 parent b9905ee commit 4e8542f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Fad/Chapter3.lean

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,17 @@ theorem inits_eq {a : Type} : ∀ xs : List a, inits₁ xs = inits₂ xs
519519
-- # Section 3.2 Random-access lists
520520

521521
def fetch {a : Type} : Nat → List a → Option a
522-
| _, [] => none
522+
| _, [] => none
523523
| k, x :: xs => if k = 0 then x else fetch (k - 1) xs
524524

525-
/-
526-
#eval [1,2,3,4].get? 2
525+
/-- info: some 3 -/
526+
#guard_msgs in
527527
#eval fetch 2 [1,2,3,4]
528-
-/
528+
529+
/-- info: some 3 -/
530+
#guard_msgs in
531+
#eval [1,2,3,4][2]?
532+
529533

530534
inductive Tree (α : Type) : Type where
531535
| leaf (n : α) : Tree α

0 commit comments

Comments
 (0)