clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Baibhav Bista 2021-02-19T00:55:28.248800Z

thanks for the tips @henryw374 @smith.adriane I totally blanked on being able to run some-function inside its own go block! That does make sense 😁

πŸ‘ 2
Baibhav Bista 2021-02-19T04:41:39.249300Z

I ended up doing it like this first a tick channel which prevents drifts over time then later, use that tick channel with another function abstracted the drift-corrector-tick-channel since I expect that will come in handy for another thing too

(def tick-channel (chan))
(def tick-interval-ms 50)
(let [start-time (js/Date.now)]
  (go-loop [i 1]
    (let [delay (- (+ start-time (* i tick-interval-ms))
                   (js/Date.now))]
      (<! (timeout delay))
      (>! tick-channel i))
    (recur (inc i))))
(go-loop []
  (<! tick-channel)
  (some-function))

Baibhav Bista 2021-02-19T04:44:55.249600Z

@smith.adriane, if I am calculating delay like this anyways, would it be necessary to have some-function be in a separate go block?

jaihindhreddy 2021-02-19T05:17:58.249800Z

@baibhavbista Doing regular ticks without drift involves a whole bunch of things, like performance.now() and document.timeline, and that's just with plain JS. Jake Archibald https://gist.github.com/jakearchibald/cb03f15670817001b1157e62a076fe95. And here's https://www.youtube.com/watch?v=MCi6AZMkxcU. This can be done through ClojureScript using JS interop. Hope this helps.

πŸ™ 1
phronmophobic 2021-02-19T05:36:08.250200Z

it depends on what some-function is. β€’ will it always execute within the delay? β€’ what if there's a bug in some-function at some point? β€’ should multiple copies of some-function be allowed to run at once? if so, how many?

phronmophobic 2021-02-19T05:38:52.250400Z

basically, it comes down to thinking about what might go wrong in the future as the code changes and planning how to fail gracefully if the best thing doesn't always happen. there's also a question of what happens if some-function throws an exception. should the repeating work continue? what if it keeps failing? etc.

πŸ‘ 1
phronmophobic 2021-02-19T05:40:10.250600Z

also. I never want to miss an opportunity to recommend reading http://erlang.org/download/armstrong_thesis_2003.pdf

πŸ™ 1
2021-02-19T16:14:57.256Z

Quick question. In clojure you can specify the print function for the repl by evaluating (clojure.main/repl :print clojure.pprint/pprint)) I can’t for the life of me find the clojurescript equivalent. I’ve tried (cljs.repl/repl :print cljs.pprint/pprint)) but cljs.repl/repl isn’t available. Any ideas? I’m just running the basic cljs repl from the webpack clojurescript tutorial.

jasmith 2021-02-19T23:59:58.262100Z

I am trying to get a clojurescript environment set up on a macos machine. 1/Cursive seems not to be working with the latest IDEA: every Clojure keyword in a source file shows up as cannot be resolved . I was able to get a remote Cursive REPL to work with shadow-cljs. The REPL works fine, just the editing is off. 2/I've been trying to get CIDER working. Highlighting works fine, but every time I try to jack-in I get the message could not start nREPL server: env: node: no such file or directory. And yes I do have node set up and on the emacs exec path. Any suggestions as to where I can turn next? Thanks!

p-himik 2021-02-23T14:26:56.063200Z

Just in case - perhaps the issue you had with Cursive has been fixed: https://clojurians.slack.com/archives/C06MAR553/p1614090076040800