mirror of
https://github.com/janet-lang/janet
synced 2025-11-24 03:04:49 +00:00
on bad type, contains? shuld return false (not error)
Note this actually changes behavior from a thin wrapper over `index-of`. This is because `(index-of 3 3)` throws "error: expected iterable type, got 3"
This commit is contained in:
@@ -1198,9 +1198,6 @@
|
|||||||
~(def ,alias :dyn ,;more ,kw))
|
~(def ,alias :dyn ,;more ,kw))
|
||||||
|
|
||||||
|
|
||||||
(defn- collection-type-error [val]
|
|
||||||
(errorf "Expected a collection (tuple|array|table|struct), but got %t" val))
|
|
||||||
|
|
||||||
(defn contains-value?
|
(defn contains-value?
|
||||||
```Checks if a collection contains the specified value.
|
```Checks if a collection contains the specified value.
|
||||||
|
|
||||||
@@ -1230,7 +1227,7 @@
|
|||||||
(nil? k) (break))
|
(nil? k) (break))
|
||||||
(set k (next collection k))))
|
(set k (next collection k))))
|
||||||
res)
|
res)
|
||||||
(collection-type-error collection)))
|
false))
|
||||||
|
|
||||||
(defn contains-key?
|
(defn contains-key?
|
||||||
```Checks if a collection contains the specified key.
|
```Checks if a collection contains the specified key.
|
||||||
@@ -1251,7 +1248,6 @@
|
|||||||
|
|
||||||
Noe that tables or structs (dictionaries) never contain null keys```
|
Noe that tables or structs (dictionaries) never contain null keys```
|
||||||
[collection key]
|
[collection key]
|
||||||
(assert (collection? collection) (collection-type-error collection))
|
|
||||||
(not (nil? (get collection key))))
|
(not (nil? (get collection key))))
|
||||||
|
|
||||||
(defn contains?
|
(defn contains?
|
||||||
@@ -1274,7 +1270,7 @@
|
|||||||
(cond
|
(cond
|
||||||
(indexed? collection) (not (nil? (index-of val collection)))
|
(indexed? collection) (not (nil? (index-of val collection)))
|
||||||
(dictionary? collection) (not (nil? (get collection val)))
|
(dictionary? collection) (not (nil? (get collection val)))
|
||||||
(collection-type-error collection)))
|
false))
|
||||||
|
|
||||||
|
|
||||||
(defdyn *defdyn-prefix* ``Optional namespace prefix to add to keywords declared with `defdyn`.
|
(defdyn *defdyn-prefix* ``Optional namespace prefix to add to keywords declared with `defdyn`.
|
||||||
|
|||||||
Reference in New Issue
Block a user