7

core.async: "Can't recur here" in ClojureScript but OK in Clojure

 2 years ago
source link: https://blog.jakubholy.net/2014/05/12/core-async-cant-recur-here-in-clojurescript-but-ok-in-clojure/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

core.async: "Can't recur here" in ClojureScript but OK in Clojure

May 12, 2014
With the latest core.async and ClojureScript (core.async "0.1.303.0-886421-alpha" and clojurescript "0.0-2202" as well as the older core.async "0.1.267.0-0d7780-alpha" and clojurescript "0.0-2173"), the following function compiles just fine in Clojure but fails in ClojureScript:

(defn cljs-cannot-recur! []
  (go-loop [v nil]
    (when-let [next-val (<! (timeout 300))]
      (recur next-val))))


The error in ClojureScript is

clojure.lang.ExceptionInfo: Can't recur here at line 23 /my/path/core.cljs ::
  {:tag :cljs/analysis-error, :file "/my/path/core.cljs", :line 23, :column 7}
             core.clj:4403 clojure.core/ex-info
             ... // very long stacktrace of 0 value


Workaround: replace (go-loop ..) with (go (loop ..)).

Another fun fact: ClojureScript's core.async lacks (at least) alt! (I did work around it by using alts! so it is not a show-stopper but still the difference is irritating and I fail to understand why it is missing.)

Oh, joy!

Are you benefitting from my writing? Consider buying me a coffee or supporting my work via GitHub Sponsors. Thank you! You can also book me for a mentoring / pair-programming session via Codementor or (cheaper) email.

Allow me to write to you!

Let's get in touch! I will occasionally send you a short email with a few links to interesting stuff I found and with summaries of my new blog posts. Max 1-2 emails per month. I read and answer to all replies.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK