cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
2019-11-27T00:40:32.427500Z

Interesting problem with JS iterables and mutability, see comment in the ticket https://clojure.atlassian.net/browse/CLJS-3199 One solution would be to realize the whole iterator at seq creation time. With this we could also use IndexedSeq instead of special ES6IteratorSeq type. The downside is that behaviour wouldn't exactly match Clojure, where iterator is realized lazily in chunks.

2019-11-27T00:48:02.430200Z

Consuming iterables lazily could be useful.

lilactown 2019-11-27T00:56:27.430900Z

I’m not sure that I (as a potential user of this) care about the difference between CLJS and CLJ w.r.t. mutation

lilactown 2019-11-27T00:58:01.431200Z

FWIW array-seq already works this way

lilactown 2019-11-27T00:59:05.431500Z

cljs.user> (def foo #js [1 2 3])
#'cljs.user/foo
cljs.user> foo
#js [1 2 3]
cljs.user> (def foo-seq (array-seq foo))
#'cljs.user/foo-seq
cljs.user> (aset foo 0 2)
2
cljs.user> foo
#js [2 2 3]
cljs.user> foo-seq
(2 2 3)

2019-11-27T08:32:03.433300Z

Also in Clojure nothing stops you from mutating nested java collections in a seq, so maybe that's fine.

2019-11-27T15:31:45.443700Z

I've chatted about this briefly with @mfikes, still would like to get more input on this. (defonce x js/v) would still eval after reloads when js/v is undefined. This happens because exists? checks for undefined, but in cljs we treat both null and undefined as nil. I propose to change the check to ns.hasOwnProperty(x) specifically for defonce, but also I'm wondering if this should go into exists? as well?

thheller 2019-11-27T15:37:53.445600Z

it should be used in neither since it will very likely interfere with :advanced

thheller 2019-11-27T15:39:03.446600Z

remember that foo.bar/x is flattened to var xT (or anything like that) in :advanced and there is no "property" to check

2019-11-27T15:39:14.446800Z

yeah that’s a good point

dnolen 2019-11-27T15:42:58.448Z

@roman01la I'm confused as to why it matters that will eval when it evals to undefined

dnolen 2019-11-27T15:43:11.448300Z

I would say this is not a problem and to avoid the pattern that allows this to happen

dnolen 2019-11-27T15:43:31.448900Z

i.e. just fix the code - we don't need to work around this

dnolen 2019-11-27T15:43:59.449700Z

re: iterators, I'm not sure that we care about the JS / Java differences here

👍 1
dnolen 2019-11-27T15:44:31.450700Z

we can't do anything about mutation - I would say not a big deal - realizing the whole thing is not a good idea

dnolen 2019-11-27T15:44:41.451100Z

I'm pretty sure you can make infinite iterables

2019-11-27T15:47:07.453200Z

I often bump into something like this (defonce init ((fn [] (js-undefined-returning-fn)))) , every time it takes me some time to figure out the problem. But I’m also fine to leave it as is.

dnolen 2019-11-27T15:50:50.454400Z

btw, I checked exists?

dnolen 2019-11-27T15:51:09.454900Z

it doesn't coerce, we use !== against 'undefined'

dnolen 2019-11-27T15:55:26.455100Z

so the problem is not nil

dnolen 2019-11-27T15:55:57.455700Z

but that the fn returned undefined and you set to that

dnolen 2019-11-27T15:56:14.456100Z

if it returned nil it would work exactly as expected

2019-11-27T15:57:00.456500Z

yes, I was talking specifically about undefined

dnolen 2019-11-27T15:57:38.457Z

ok sorry, wasn't sure

dnolen 2019-11-27T15:58:22.458100Z

right I think this is just too trivial to solve in userland

dnolen 2019-11-27T15:58:32.458500Z

a helper fn, or a macro

2019-11-27T15:59:38.459200Z

This also popped out in https://clojure.atlassian.net/browse/CLJS-3195, I think the patch there should still make sure that “no value” is null , not undefined

mfikes 2019-11-27T16:02:04.460300Z

For CLJS-3195, since null and undefined are both aliased to nil, for ClojureScript code things should generally be OK. But, the risk is that someone passes such a value into JavaScript that cares.

dnolen 2019-11-27T16:07:11.461300Z

hrm my first impression is ergh re: 3195

dnolen 2019-11-27T16:07:27.461600Z

probably not going to consider that one too problematic

dnolen 2019-11-27T16:08:01.462400Z

I'm not really interested in futzing around with undefined anymore - so I would spend effort elsewhere

👍 1