From 5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 31 Aug 2025 23:33:22 -0400 Subject: Switch to using optional return values for list indexing. --- docs/lists.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'docs/lists.md') diff --git a/docs/lists.md b/docs/lists.md index dfb64aad..d12a0b5b 100644 --- a/docs/lists.md +++ b/docs/lists.md @@ -62,24 +62,23 @@ last item, `-2` is the second-to-last, and so on. ```tomo list := [10, 20, 30, 40] >> list[1] -= 10 += 10? >> list[2] -= 20 += 20? + +>> list[999] += none >> list[-1] -= 40 += 40? >> list[-2] -= 30 += 30? ``` If a list index of `0` or any value larger than the length of the list is -used, it will trigger a runtime error that will print what the invalid list -index was, the length of the list, and a stack trace. As a performance -operation, if list bounds checking proves to be a performance hot spot, you -can explicitly disable bounds checking by adding `list[i; unchecked]` to the -list access. +used, a `none` value will be returned. ## Iteration -- cgit v1.2.3