This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-28
Channels
- # beginners (33)
- # boot (58)
- # cider (21)
- # cljs-dev (197)
- # cljsrn (112)
- # clojure (136)
- # clojure-belgium (5)
- # clojure-dev (57)
- # clojure-greece (1)
- # clojure-italy (3)
- # clojure-russia (6)
- # clojure-spec (148)
- # clojure-uk (54)
- # clojurescript (29)
- # cursive (24)
- # datomic (36)
- # devops (4)
- # emacs (11)
- # figwheel (1)
- # graphql (18)
- # hoplon (6)
- # leiningen (2)
- # luminus (4)
- # off-topic (7)
- # om (4)
- # onyx (27)
- # precept (1)
- # protorepl (12)
- # quil (1)
- # re-frame (28)
- # reagent (10)
- # ring (9)
- # robots (1)
- # rum (2)
- # slack-help (5)
- # spacemacs (16)
- # sql (16)
- # untangled (16)
- # vim (3)
- # yada (2)
Somehow this commit: https://github.com/clojure/clojurescript/commit/940b6c8ffd98754f3dfc0e7fbe0878235f62debd
Made CLJS emit tons of with-meta
call with ::analyzed
true.
oh I think I know what you mean, we don’t elide that meta so for literals it will drop meta
var new_root = (function() {
var fexpr__11505 = cljs.core.with_meta(((function(tcoll__$1) {
/// SNIP
})(tcoll__$1))
,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$cljs$analyzer_SLASH_analyzed,true], null));
return (fexpr__11505.cljs$core$IFn$_invoke$arity$2 ? fexpr__11505.cljs$core$IFn$_invoke$arity$2(self__.shift,self__.root) : fexpr__11505(self__.shift,self__.root));
})();
Is there a ticket yet for this:
(defn foo
([a & b] 0)
([a b & c] 1))
(defn foo
([a b c d e] 0)
([a b & c] 1))
Both of these don't emit any warning/error. Just trying to avoid problems like we had with the variadic protocol usage.
Changes to IFind: https://dev.clojure.org/jira/browse/CLJS-2136
I wanted to do this before there were too many in-the-wild -find impls that assumed a contains? was already done
@favila looks OK I left my only comment in the ticket - revert the docstring change to the protocol and I’ll push it through
Would you accept the same docstring for find
on -find
itself? (not the protocol). I.e.
(defprotocol IFind
"Protocol for implementing entry finding in collections."
(-find [coll k] "Returns the map entry for key, or nil if key not present."))
All other protocols in the area (ILookup, IAssociative, IMap, etc) do this. And the confusion for implementors was the point of the patch
(defprotocol IMap
"Protocol for adding mapping functionality to collections."
#_(-assoc-ex [coll k v])
(^clj -dissoc [coll k]
"Returns a new collection of coll without the mapping for key k."))
(^clj -assoc [coll k v]
"Returns a new collection of coll with a mapping from key k to
value v added to it.")
So you think implementors will never be unclear whether they might to return nil? even though this has already happened in CLJS-2013?
@dnolen Updated patch. But still disagree, and don't understand why almost all other collection protocols in core document their return values but this one cannot
would adding "Returns the map entry for key, or nil if key not present."
to the -find
method itself be acceptable?
@tmulvaney It doesn't. Those impls were find and working, I just made them use case
instead
ah I meant this part in the patch:
IFind
(-find [coll k]
- (.entry-at coll k))
+ (when-some [found (.entry-at coll k)]
+ [(.-key found) (.-val found)]))
@tmulvaney nevermind, you may be right. Running the tests again
@tmulvaney what is going on with (assoc-n
in collections-test 666?https://github.com/clojure/clojurescript/blob/master/src/test/cljs/cljs/collections_test.cljs#L666
anyway, you were right, RedNode and BlackNode are fine as-is, no need to pull key and val out of them
no worries. That patch taught me about the existence of when-some/if-some. My new favourite binding forms 😀
@dnolen @tmulvaney https://dev.clojure.org/jira/browse/CLJS-2136 updated. should be ready now but review always appreciated
IFind
(-find [coll k]
(let [idx (array-map-index-of coll k)]
(when-not (== idx -1)
[(aget arr idx) (aget arr (inc idx))])))
looks like find on vector works correctly in the patch with respect to non integer keys
get
should probably be updated to do the same as (get [0 1 2 3] 1.42)
returning 1 is weird
I'm not sure what it's supposed to do. could be 1) exactly what clj does for all input, 2) only safely-representable longs in js (53-bit or less), 3) what the docstring says, any number without decimal components.
but there's a test (is (= (integer? 1e308) false))
which makes 3 not work, but if you change it to do that, then other tests fail
@tmulvaney @favila let’s rewind
@dnolen we're not really talking about the -find patch at this point anymore I think. @tmulvaney noticed that whatever I do in vector -find would probably be good in vector -lookup WRT float keys
(neither does clojure in some cases, so I'm with dnolen here)
user=> (nth [1 2 3] 0.2)
1
I relied on -find of v working properly. Do I need another bounds check to ensure I'm within the window subvec has?
@dnolen removing the bounds check is going to cause at least one test to fail: (is (= (find [1 2 3] 1.2) nil))
in collections-test
Ah I see now @rauh, I needed (neg? n)
to make sure no one escapes the start of the subvec window with a negative number
I think we should copy the existing code over:
IIndexed
(-nth [coll n]
(if (or (neg? n) (<= end (+ start n)))
(vector-index-out-of-bounds n (- end start))
(-nth v (+ start n))))
IMHO, copying the impl and 1:1 and even writing (if ... nil (-find ...))
might be easier for maintenance
@dnolen would be good to test when start is not 0, would capture any errors with forgetting start + n, indexes not being rewritten, viewing to left of subvec window but not vector, etc
(let [s (subvec [0 1 2 3 4] 1 3)]
(testing "IFind"
(is (= (find s 0) [0 1]))
(is (= (find s 1) [1 2]))
(is (= (find s 2) nil))
(is (= (find s -1) nil))))
(-find [coll n]
(when (and (not (neg? n))
(< (+ start n) end))
(when-some [found (-find v (+ start n))]
[(+ start (-key found)) (-val found)])))
--- a/src/main/cljs/cljs/core.cljs
+++ b/src/main/cljs/cljs/core.cljs
@@ -5526,7 +5526,7 @@ reduces them without incurring seq initialization"
(-find [coll n]
(when (and (not (neg? n))
(< (+ start n) end))
- (-find v (+ start n))))
+ [n (-lookup v (+ start n))]))
IVector
(-assoc-n [coll n val]
diff --git a/src/test/cljs/cljs/collections_test.cljs b/src/test/cljs/cljs/collections_test.cljs
index 14dfa56..dfbfb82 100644
--- a/src/test/cljs/cljs/collections_test.cljs
+++ b/src/test/cljs/cljs/collections_test.cljs
@@ -99,10 +99,10 @@
(testing "rseq equality"
(is (= (rseq sv1) '(1)))
(is (nil? (rseq sv2)))))
- (let [s (subvec [0 1 2 3] 0 2)]
+ (let [s (subvec [0 1 2 3 4] 1 3)]
(testing "IFind"
- (is (= (find s 0) [0 0]))
- (is (= (find s 1) [1 1]))
+ (is (= (find s 0) [0 1]))
+ (is (= (find s 1) [1 2]))
(is (= (find s 2) nil))
(is (= (find s -1) nil))))
)