Fork me on GitHub
#clojurescript
<
2016-06-07
>
dnolen01:06:32

@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

dnolen01:06:54

would prefer to stop adding compiler options

dnolen01:06:19

@wilkerlucio: if you can add that to CLJS-1666 that would be helpful

wilkerlucio02:06:32

@dnolen: sure, should I add the full stack as well or just the description?

leeondamiky08:06:17

How would I go about pretty printing cljs.spec error output in the browser console?

cky11:06:15

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.Longs). I have several questions:

cky11:06:56

1. Is using a lazy seq a good way to implement this, or is there a better approach?

cky11:06:04

2. Assuming this is a good approach, is this a good implementation?

cky11:06:40

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 …)?

cky11:06:48

(Having written all this out, I’m tempted to post this as a question on Code Review Stack Exchange, also. simple_smile)

cky11:06:18

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

peeja14:06:36

@mfikes: Good thought, and it was false, but binding it to true doesn't appear to fix it. Oh well.

mfikes14:06:24

@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.

peeja14:06:41

Oh, good thought…

peeja14:06:30

No, unfortunately it's 72, and the length of the output is 42739. 😛

settinghead14:06:45

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

settinghead14:06:39

also, the error thrown is always a giant one-line blob. would be nice if it’s pprint'ed

dnolen14:06:58

@settinghead: I don’t understand it’s “hard to see which part is throwing it"

dnolen14:06:10

the stack trace tells you exactly all the calls leading up to where it failed

dnolen14:06:35

also “giant one-line” blob what is this referring to?

dnolen14:06:06

a screenshot or something would help

settinghead15:06:43

however, if the :val is say a giant map, it becomes harder to read when everything is serialized in one single line

dnolen15:06:35

@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

dnolen15:06:03

also nothing is stopping fancier tooling from doing this stuff

dnolen15:06:35

you can probably even do this yourself with a window level exception handler during dev

settinghead15:06:50

@dnolen: makes sense. will try. thanks

peeja15:06:45

I figured out the pprint problem! I had an om/MapCursor, which pprint doesn't natively know to treat like a map

dnolen22:06:48

@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

dnolen22:06:02

re: JSValue problem with Transit JSON analysis caches

wilkerlucio22:06:17

sure, going to try now

wilkerlucio22:06:33

whats the command to build from the sources?

dnolen22:06:39

./script/build

wilkerlucio22:06:20

@dnolen: thanks, and the compilation is working on my project 🙂

dnolen22:06:40

@wilkerlucio: ok so that particular issue is fixed for you?

dnolen22:06:17

@wilkerlucio: I would try running a Figwheel REPL as well and requiring something etc.

dnolen22:06:24

if you have that setup in your project

wilkerlucio22:06:49

ok, I'll try that

wilkerlucio22:06:52

I think it's all working, I tried cleaning my build and also loading a file that contains #js tags, all worked

dnolen23:06:10

@wilkerlucio: ok, cool thanks much for the check!

wilkerlucio23:06:26

no problem, you'r welcome

dnolen23:06:24

@jr re: I’d like a bit more information about what is going on

dnolen23:06:39

somehow non-compilable things are getting into the analysis cache which really should never happen

dnolen23:06:57

something that would help me would be to know where in the structure of the cache this is happening for you

dnolen23:06:18

if you use a previous version of ClojureScript and grep through the EDN analysis cache for #object that would explain a lot of things