This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-31
Channels
- # announcements (6)
- # babashka (32)
- # beginners (78)
- # biff (11)
- # calva (7)
- # clj-kondo (20)
- # clojure (35)
- # clojure-europe (10)
- # clojure-nl (4)
- # clojure-norway (8)
- # clojure-uk (2)
- # clojurescript (41)
- # conjure (14)
- # core-async (10)
- # cursive (7)
- # datomic (12)
- # deps-new (4)
- # emacs (15)
- # fulcro (48)
- # gratitude (11)
- # hugsql (1)
- # hyperfiddle (3)
- # introduce-yourself (3)
- # jobs (3)
- # klipse (2)
- # off-topic (7)
- # polylith (30)
- # reitit (1)
- # remote-jobs (1)
- # reveal (8)
- # scittle (4)
- # shadow-cljs (40)
- # squint (13)
- # tools-deps (7)
- # xtdb (7)
In Javascript there is a concept of ArrayLike
Array.from({"0": "a", "1": "b"})
// []
Array.from({"0": "a", "1": "b", "length": 2})
// ['a', 'b']
Is that something which makes sense for clava
I mean, do we want to recognise array like instead of treating them as maps
It was useful for things like document.getElementsByTagName("li")
and arguments
inside a function. But now a days they all support Symbol.iterator so they are not a problem.
for example
(vec {"0" 1 "length" 1})
=> [["0 1] ["length" 1]]
(js/Array.from {"0" 1 "length" 1})
=> [1]
clava handles js objects as maps so the above is as expected. I am only asking whether it would make sense to treat ArrayLike as iterable. The workaround is also very simple. Just use Array.from
yes, and numbers as keys
I beleive there is no official spec of ArrayLike. In the past there were certain objects which are not exactly array but have arraylike properties. For example HTMLCollection
. It has a length property but it is not an array. But now I noticed that it has [Symbol.iterator]
on it so it still works with clava as expected.