1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-23 23:10:26 +00:00

Warn about index-of type errors when not iterable

This is just documentation of existing behavior, it does not change anything.

The reason index-of throws a type error on non-iterable types is because `next` does.
This is hardcoded into the JOP_NEXT opcode (see src/core/value.c:janet_next_impl).

Unfortunately, there is currently no corresponding `iterable?` check.
This commit is contained in:
Techcable 2022-08-26 14:24:54 -07:00
parent 765eb84c33
commit 699f9622d7
No known key found for this signature in database
GPG Key ID: D7B98ADFF827CD17

View File

@ -1072,7 +1072,9 @@
(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.``
Returns `dflt` if not found.
This will throw an error if `ind` is not iterable.``
[x ind &opt dflt]
(var k (next ind nil))
(var ret dflt)