This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-22
Channels
- # announcements (10)
- # babashka (40)
- # beginners (192)
- # calva (9)
- # cider (2)
- # clj-kondo (9)
- # clojure (69)
- # clojure-dev (15)
- # clojure-europe (29)
- # clojure-gamedev (6)
- # clojure-italy (2)
- # clojure-nl (41)
- # clojure-spec (49)
- # clojure-uk (11)
- # clojurescript (68)
- # conjure (1)
- # cryogen (20)
- # cursive (37)
- # data-oriented-programming (10)
- # data-science (4)
- # datahike (7)
- # datomic (8)
- # depstar (14)
- # emacs (7)
- # events (2)
- # figwheel-main (1)
- # fulcro (81)
- # honeysql (22)
- # hugsql (5)
- # juxt (3)
- # leiningen (8)
- # lsp (314)
- # malli (20)
- # meander (15)
- # membrane (20)
- # mid-cities-meetup (11)
- # practicalli (2)
- # reagent (2)
- # remote-jobs (2)
- # ring-swagger (1)
- # rum (3)
- # sci (21)
- # shadow-cljs (52)
- # startup-in-a-month (1)
- # testing (9)
- # tools-deps (41)
- # vim (8)
- # xtdb (4)
Hi! Does ClojureScript “intentionally” treat a leading dot (.) as potentially the first character in a floating-point literal? Clojure treats “.” as a symbol character, but based on what I’m seeing in lumo, ClojureScript doesn’t (always):
$ lumo
Lumo 1.10.1
ClojureScript 1.10.520
Node.js v11.13.0
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Exit: Control+D or :cljs/quit or exit
cljs.user=> .1
0.1
cljs.user=>
I am having an issue with advanced
compilation and goog.string.format. I think a type hint would solve it but not sure where to put it. I tried (gstring/format "%.2f" ^number v)
but it is not working
what's not working? is there an error? is there a stack trace?
Sorry I'm only replying now, there was a stack trace starting with something like Cc.format
is not a function and a whole minified stack trace under
@UGH9KH1DF , what do your requires for that namespace look like? are you requiring goog.string
?
oh wait, what namespace are you trying to reference? It doesn't look like goog.string.format exists, https://google.github.io/closure-library/api/goog.string.html
maybe you just want (format "%.2f" v)
When I tried to use format the compiler was telling me that format is not part of cljs.core though
according to this answer, https://stackoverflow.com/a/34668677
you need to require both [goog.string :as gstring]
and [goog.string.format]
Ohhhh ok thank you! Will try, but I don't get why are both requires needed :thinking_face:
it look it's just an odd implementation choice by goog.string.format, https://github.com/google/closure-library/blob/4f18d359603b23dd4db402d62d796ea0e40ae48f/closure/goog/string/stringformat.js#L17
the format function is written in a separate module, goog.string.format
, but the function is added to goog.string
namespace, https://github.com/google/closure-library/blob/4f18d359603b23dd4db402d62d796ea0e40ae48f/closure/goog/string/stringformat.js#L33
hi, a total newbie here... in lein we use lein new app testing
to create a clojure project called testing. but how to create clojurescript project with leinengen?
Hi Adrian, you could try one of the templates here: https://clojurescript.org/guides/project-templates
ohhhh, thank you @U01M742UT8F, will try on this :D
Hello persistent maps and transients maps are expected to be 3x slower than js-objects? i did a simple benchmark that i just added members
"Elapsed time: 3887.477828 msecs" (persistent)
"Elapsed time: 3352.944982 msecs" (transient)
"Elapsed time: 1113.168076 msecs" (js-object)
I did the same with vectors,but the difference there was small transient was 5sec,js-array was 4sec
(defn p-m [size]
(loop [i 0
v {}]
(if (= i size)
v
(recur (inc i) (assoc v (str i) i)))))
(defn t-m [size]
(loop [i 0
v (transient {})]
(if (= i size)
(persistent! v)
(recur (inc i) (assoc! v (str i) i)))))
(defn j-m [size]
(loop [i 0
v (js/Object)]
(if (= i size)
v
(recur (inc i) (do (aset v (str i) i) v)))))
has anyone had any luck integrating npm dependencies (in this case https://nivo.rocks/) via figwheel-main? I basically took the clj -X:new clj-new/create :template figwheel-main :name example/example :args '["+npm-bundle","--reagent"]'
command and added the npm dependency, ran the npm install and tried to import it e.g. (:require ["@nivo/pie" :refer [ResponsivePie]])
and adapt it via reagent [:> ...]
however (maybe to be expected) I'm missing something as it yields Uncaught TypeError: example.node$module$_CIRCA_nivo$pie is undefined
funny, react-bootstrap does work with the same mechanism, maybe the "@" symbol?
huh, nevermind got it to work by restarting, I guess the module wasn't picked up dynamically or something
thank you thheller if someone knows if i can do something about it, to reduce the 3x , tell me if you can
but you are comparing persistent datastructures to a mutable object. that is hardly fair given the different features they provide.
you can after all just use JS objects when that really matters and you don't need all the stuff the maps give you.
i noticed that the slow is the HashMap, ArrayMap is fast similar to js-object , from my code the ArrayMap auto becomes HashMap if 9 or more members
There is no built-in way without modifying the ClojureScript implementation code itself to do that.
Note that ArrayMap always do linear scanning through keys when you do lookups on them. If your maps are being looked up more frequently than they are being constructed, using ArrayMap for larger maps might make your overall performance worse.
is there a way to say keep it ArrayMap for lets say 30 members? (my maps are almost never bigger)
@takis_ If your maps are never more than 30 members, please do yourself a favor and ignore performance
i think this is the code
(set! (.-HASHMAP_THRESHOLD ObjMap) 8)
anyway thank you all : )I wonder what the wider context of your performance issue is. It might be that there's another way to solve it.
i checked this https://github.com/mfikes/cljs-bean it looks like it does what i need,easy interop and fast , thank you for information i am new in clojurescript
Today I learned that a ClojureScript object could mimic a JavaScript object (Thank you @thheller) via JavasScript proxy. I wrote a small naive piece of code for that
(defn proxy [m]
(js/Proxy. m #js {:get (fn [target prop]
(let [prop' (if (vector? target)
(js/parseInt prop)
(keyword prop))]
(let [v (or (get target prop')
(get target prop))]
(if (coll? v)
(proxy v)
v))))}))
Example of usage:
(def n {:a {:b [{:c {:d 1}}]}})
(def m (proxy n))
And in JavaScript
m.a.b[0].c.d // 1
It is quite similar @mfikes’s bean but in the other direction.
Do you guys think it a function like proxy
could be useful?
Awesome! Thank you pithyless. Another great contribution by @wilkerlucio
With https://github.com/mfikes/cljs-bean and https://github.com/wilkerlucio/js-data-interop conversion from ClojureScript to JavaScript back and forth is super efficient. Thank you @mfikes and @wilkerlucio
you'r welcome, I just like to add bit on the maturity of this library (js-data-interop), I only used for some experiments, and I don't know anybody that used this in prod, please let me know if you find some issues on the approach
Hacking a bit with js-data-interop
It doesn’t work with string keys in maps
(.-a (jsp {"a" 1})) ;; => nil
I guess it would also make sense to support symbols then, assuming you want to be as close to clj->js
as possible.
As a side note, there's also IEncodeJS
which IMO makes 100% compatibility with clj->js
unfeasible.
what’s IEncodeJS?