mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 09:47:17 +00:00
Remove documentation on type error from index-of
Three reasons: 1. This same behavior is not documented on the `next` function 2. This function does not throw the error directly, it only throws an error because `next` does. 3. Following the same idea as the previous commit, this behavior is more or less implementation-defined for nonsensical types > In dynamic languages, the usual idea is garbage in, garbage out. Various other documentation cleanup.
This commit is contained in:
parent
a20612478e
commit
c099ec05ee
@ -1069,9 +1069,7 @@
|
|||||||
(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)
|
||||||
@ -1219,18 +1217,16 @@
|
|||||||
This includes buffers, dictionaries, arrays, fibers, and possibly abstract types.
|
This includes buffers, dictionaries, arrays, fibers, and possibly abstract types.
|
||||||
|
|
||||||
For tables and structs, this checks the values, not the keys.
|
For tables and structs, this checks the values, not the keys.
|
||||||
For arrays, tuples (and any other iterable type), this simply checks if any of the values are eqyak.
|
For arrays, tuples (and any other iterable type), this simply checks if any of the values are equal.
|
||||||
|
|
||||||
For buffer types (strings, buffers, keywords), this checks if the specified byte is present.
|
For buffer types (strings, buffers, keywords), this checks if the specified byte is present.
|
||||||
This is because, buffer types (strings, keywords, symbols) are iterable types, with byte values.
|
This is because, buffer types (strings, keywords, symbols) are simply sequences, with byte values.
|
||||||
This means they will also work with `next` and `index-of`.
|
This means they will also work with `next` and `index-of`.
|
||||||
|
|
||||||
However, it also means this function will not check for substrings, only integer bytes.
|
However, it also means this function will not check for substrings, only integer bytes (which could be unexpected).
|
||||||
In other words is `(contains? "foo bar" "foo")` is always false, because "foo" is not an integer byte
|
In other words is `(contains? "foo bar" "foo")` is always false, because "foo" is not an integer byte
|
||||||
If you want to check for a substring in a buffer, then use `(not (nil? (string/find substr buffer)))`
|
If you want to check for a substring in a buffer, then use `(truthy? (string/find substr buffer))`,
|
||||||
|
or just `(if (string/find substr buffer) then else)`
|
||||||
If the type is not iterable, this will return false.
|
|
||||||
This is in contrast to `index-of` and `next`, which will throw a type error.
|
|
||||||
|
|
||||||
In general this function has O(n) performance, since it requires iterating over all the values.
|
In general this function has O(n) performance, since it requires iterating over all the values.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user