This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-07
Channels
- # admin-announcements (4)
- # beginners (63)
- # boot (67)
- # clara (29)
- # cljs-dev (38)
- # cljsjs (10)
- # clojars (7)
- # clojure (336)
- # clojure-belgium (3)
- # clojure-dev (22)
- # clojure-greece (30)
- # clojure-nl (1)
- # clojure-russia (9)
- # clojure-spain (3)
- # clojure-spec (169)
- # clojure-uk (12)
- # clojurescript (45)
- # clojurex (4)
- # core-matrix (3)
- # cursive (58)
- # datascript (3)
- # datomic (18)
- # events (38)
- # hoplon (228)
- # immutant (5)
- # lambdaisland (6)
- # leiningen (3)
- # luminus (8)
- # off-topic (11)
- # om (113)
- # om-next (2)
- # onyx (10)
- # parinfer (7)
- # planck (22)
- # re-frame (11)
- # reagent (25)
- # robots (7)
- # spacemacs (3)
- # specter (10)
- # yada (3)
@wilkerlucio: @jr: I’m collecting more information about cases like this, I’m curious whether just by covering the obvious stuff like JSValue and Var we’ll be good enough
@wilkerlucio: if you can add that to CLJS-1666 that would be helpful
@dnolen: sure, should I add the full stack as well or just the description?
How would I go about pretty printing cljs.spec error output in the browser console?
I’m currently in the process of implementing PCG (http://www.pcg-random.org/), in particular the pcg32
variant, using ClojureScript. Because Clojure tends to eschew mutable state, I’ve chosen to implement the generator as a seq:
(defn- bit-rotate-right [x n]
(bit-or (unsigned-bit-shift-right x n)
(bit-shift-left x (- n))))
(defn- unsigned [x]
(aget (.of js/Uint32Array x) 0))
(defn make-pcg32-seq [seed seqid]
(let [state (or seed (generate-seed))
increment (if seqid
(.or (.shiftLeft seqid 1) (.getOne Long))
default-increment)]
(map #(-> %
(.shiftRightUnsigned 18)
(.xor %)
(.shiftRightUnsigned 27)
.toInt
(bit-rotate-right (.toInt (.shiftRightUnsigned % 59)))
unsigned)
(iterate #(-> %
(.multiply default-multiplier)
(.add increment))
state))))
(both arguments to the function, if given, are goog.math.Long
s). I have several questions:3. I also have a function that implements the equivalent of rand-int
using a backing random-seq:
(defn bounded-random [random-seq bound]
(let [threshold (js-mod (unsigned (- bound)) bound)]
(loop [rs random-seq]
(if (>= (first rs) threshold)
[(js-mod (first rs) bound) (rest rs)]
(recur (rest rs))))))
a) Is this a good implementation approach? Note that I always have to return the “next” point in the random-seq unless there is some mutable state I can work with.
b) Assuming it’s a good approach, would the below be a better implementation? (Note: not tested yet.)
(defn bounded-random [random-seq bound]
(let [threshold (js-mod (unsigned (- bound)) bound)]
(some #(if (>= (first %) threshold)
[(js-mod (first %) bound) (rest %)])
(iterate next random-seq))))
c) If so, is there a more idiomatic way to write (iterate next …)
?(Having written all this out, I’m tempted to post this as a question on Code Review Stack Exchange, also. )
If you’re curious about the definition of things like generate-seed
, default-increment
, default-multiplier
, etc., here’s the whole source file: https://gitlab.com/cky/emojisweeper/blob/master/src/cljs/emojisweeper/pcg.cljs
@mfikes: Good thought, and it was false
, but binding
it to true
doesn't appear to fix it. Oh well.
@peeja The only other (unfounded) thought I have is that perhaps you are expecting pprint
to wrap but it is not doing so owing to *print-right-margin*
being set to a large value.
cljs.spec
question: is there a way to see the stack trace of the errors from (spec'ed) function? i can see the errors and explained message in the browser console, but sometimes find it difficult to track which part of code is throwing it
also, the error thrown is always a giant one-line blob. would be nice if it’s pprint'ed
@settinghead: I don’t understand it’s “hard to see which part is throwing it"
however, if the :val
is say a giant map, it becomes harder to read when everything is serialized in one single line
@settinghead: yeah I’m not sure about pretty printing - but will think about - some of these decisions need to bounced around with what is happening in clojure.spec
you can probably even do this yourself with a window level exception handler during dev
@dnolen: makes sense. will try. thanks
I figured out the pprint
problem! I had an om/MapCursor
, which pprint
doesn't natively know to treat like a map
@wilkerlucio: when you have some time if you could try master that would be helpful - hopefully it just works - if not I’d like to find a minimal case to repro that doesn’t involve other stuff
sure, going to try now
whats the command to build from the sources?
@dnolen: thanks, and the compilation is working on my project 🙂
@wilkerlucio: ok so that particular issue is fixed for you?
@wilkerlucio: I would try running a Figwheel REPL as well and requiring something etc.
ok, I'll try that
I think it's all working, I tried cleaning my build and also loading a file that contains #js tags, all worked
@wilkerlucio: ok, cool thanks much for the check!
no problem, you'r welcome
somehow non-compilable things are getting into the analysis cache which really should never happen