mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 16:00:27 +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:
parent
765eb84c33
commit
699f9622d7
@ -1072,7 +1072,9 @@
|
|||||||
(defn index-of
|
(defn index-of
|
||||||
``Find the first key associated with a value x in a data structure, acting like a reverse lookup.
|
``Find the first key associated with a value x in a data structure, acting like a reverse lookup.
|
||||||
Will not look at table prototypes.
|
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]
|
[x ind &opt dflt]
|
||||||
(var k (next ind nil))
|
(var k (next ind nil))
|
||||||
(var ret dflt)
|
(var ret dflt)
|
||||||
|
Loading…
Reference in New Issue
Block a user