From 3d03d083c77729b9a36e3cba9edcdc47fba824cd Mon Sep 17 00:00:00 2001 From: sogaiu <33044872+sogaiu@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:56:24 +0000 Subject: [PATCH] Improve index-of docstring (#1809) Co-authored-by: sogaiu <983021772@users.noreply.github.com> --- src/boot/boot.janet | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 67603b86..f8b9be1a 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1226,15 +1226,20 @@ ret) (defn index-of - ``Find the first key associated with a value x in a data structure, acting like a reverse lookup. - Will not look at table prototypes. - Returns `dflt` if not found.`` - [x ind &opt dflt] - (var k (next ind nil)) + `` + Find the first key associated with a value `val` in `x`, acting like + a reverse lookup. Will not look at dictionary prototypes. If not + found, returns `dflt` if provided and `nil` otherwise. + + `x` can be a bytes, indexed, dictionary, fiber, or abstract type + with suitable `get` and `next` methods. + `` + [val x &opt dflt] + (var k (next x nil)) (var ret dflt) (while (not= nil k) - (when (= (in ind k) x) (set ret k) (break)) - (set k (next ind k))) + (when (= (in x k) val) (set ret k) (break)) + (set k (next x k))) ret) (defn- take-n-slice