~{} returns -1 in JavaScript, don't ask me how I know
> ~"foo"
-1
> ~NaN
-1
> ~["foobar"]
-1
seems to do the same for all non-numbers?I can't recall ever using ~ operator in JS
yes
well, ~{} is used in js* ;)
Work in progress but got this working:
(get (assoc {} :a 1) :a)
=>
{ ...{}, a: 1 }["a"]
It can be inferred that {} is an object, so both assoc and get compile down to low level JSoh you could probably do the same for conj and vectors - in my datastar-expr library I had these implemented in terms of merge and concat (I had the benefit of assuming an even thinner translation barrier than squint's and narrowing the semantics of these functions, ie no clever inference needed)
(mapv emit `[(merge) (merge m1) (merge m1 m2)
(concat) (concat v1) (concat v1 v2)])
;; => ["{}" "{...m1}" "{...m1,...m2}"
;; "[]" "[...v1]" "[...v1,...v2]"]
(mapv emit `[(merge m {:a 1}) (merge {:a 1} m) (merge {} m {})
(concat xs [1 2 3]) (concat [1 2 3] xs) (concat [] xs [])])
;; => ["{...m,'a':1}" "{'a':1,...m}" "{...m}"
;; "[...xs,1,2,3]" "[1,2,3,...xs]" "[...xs]"]
(emit `(assoc m :k1 v1 k2 v2)) ;; => "{...m,'k1':v1,[k2]:v2}"
(emit `(conj xs 1 2)) ;; => "[...xs,1,2]"
(emit `(cons 1 xs)) ;; => "[1,...xs]"
(emit `(list* 1 2 3 xs)) ;; => "[1,2,3,...xs]"
(emit `(get (assoc {} :a 1) :a)) ;; => "({'a':1}).a"yes, planning to do that next
yeah thanks for the merge idea, that's neat
feel free to post these examples here: https://github.com/squint-cljs/squint/issues/728
I mean, only the merge and concat ones, the rest isn't going to work in squint since it has a distinct list type
yeah I guess it depends how faithful to clojure's semantics you want to be re. concat returning a lazy seq
(oh nice, I realised my current impl for (get m k nf) => "m[k]??nf" , the in operator is definitely a better way to go)
yes, in :)
Every time I see a Eucalypt example I have the same feeling: "I can't believe this works".
oh, I think I found a bug in take-last? negative numbers should return (), I'm not sure what the Math.abs is doing there https://squint-cljs.github.io/squint/?repl=true&src=KHRha2UtbGFzdCAtMSBbMSAyIDMgNCA1XSk%3D
thanks!