Fork me on GitHub

Why cljs has a :invalid-arithmetic warning and no render, when clj no?

493 | (def A-to-D (map char (range (int \A) 69)))
 cljs.core/bit-or, all arguments must be numbers, got [string number] instead


In ClojureScript \A is just a one character string “A” There’s most likely a better way, but I usually use something like:

#?(:clj (int \A) :cljs (.charCodeAt \A 0))


Thank you @U051N6TTC, I didn't find nothing about that before and I would not been able to find it by myself 🙏 .


Okay so the last line says with function needs to be used based on the compiler, right?


That’s conditional compilation, yes. It can only go into a`.cljc` file. It won’t work in .clj files (those are for Clojure only), .cljs files (ClojureScript only), or at a repl (which is whatever type of repl it is)

👍 3

This is a very basic question, but I don’t know why it isn’t working. So I have an anchor tag to “/creators” on my webpage:

[:a {:href "/creators" :style {:font-size 40 :max-width 300 :padding "1%" :cursor :pointer :border "1px solid gray" :background-color :black :color :white}} "Find creators to invest in"]
I have the reitit routes:
(def router
    [#_["/" {:name        :home
           :view        #'home-page
           :controllers [{:start (fn [_] (rf/dispatch [:page/init-home]))}]}]
     ["/" {:name :landing
           :view #'landing}]
     ["/about" {:name :about
                :view #'about-page}]
     ["/creators" {:name :creators
                  :view #'creators}]]))
Here’s init!
(defn init! []
and here’s start-router. rfe refers to reitit.frontend.easy:
(defn start-router! []
The problem is that /creators and /about routes are giving 404 even thought the root route / is working. Why might this be?


The following assumes that you want to use relative paths instead of URL fragments, like "#creators". In SPAs, routes are two-fold - there's a frontend side and there's a backend side. You have to configure 3 things: 1. Routes themselves on the frontend 2. HTML5 history on the frontend (via e.g. or something else) 3. The very same routes on the backend Given that you receive HTTP 404, you don't have the third item implemented. And given that your browser is trying to reload the page at the new URL instead of just changing your app's state, you also don't have the second item implemented.


Hi p-himik!! This is interesting to me too. This is the first time I've seen the routing split into 3 types. Do you know if there are any links where I can find more information on each of these kinds. So far I've seen very little documentation about routing and is dependent on the web framework you use.... alas!!


There are two types of routing, not 3. The second item above is basically just a way to tell your browser to not reload the page. No clue about any reading materials, sorry. But there's not that much to understand here. The frontend routes work when HTML5 history is set up - when set up correctly, when dictate what code runs on the frontend when the current URL path changes. By themselves, no requests to the backend are made. The backend routes work when you make requests to the backend. If there's a route that exists on the frontend but not on the backend, you'll see HTTP 404 after making a request to that route (e.g. by not setting up HTML5 history and navigating to that route or by navigating to that route and hitting Refresh). And of course backends can have more routes than frontends to allow some "hidden" pages or, more commonly, data fetching via AJAX. All the routes that the backend has in sync with the frontend can serve the exact same data - it will be routed on the frontend to the correct state. Or you can add that data along with the main HTML that you serve to speed up page loading.

👍 2

Currently trying to assign a value asynchronously to an atom.

(def temp-1 (r/atom ()))

(a/go (let [response (a/<! (http/get all-posts-uri))]
        (doseq [post (map #(str post-route %)
                          (js->clj (:body response)))]
          (reset! temp-1 (r/atom
                           (:body (a/<! (http/get post))))))))
The http namespace is cljs-http.client from


Here’s what happens when I try to deref the atom.> @temp-1


Don't wrap it into another r/atom - you have to pass the actual value to reset!. Also, don't call reset! in a doseq - you will overwrite the previous results. Finally, are you sure that (:body response) is a non-empty collection?


Oh yeah, true. I was using prn to see the response body so that’s why doseq was still in there.


I also tested this, not sure I’m getting warmer.

(a/go (let [response (a/<! (http/get all-posts-uri))]
        (reset! temp-1
                (for [post (map #(str post-route %)
                                (js->clj (:body response)))]
                  (:body (a/<! (http/get post)))))))


Not really. for returns a lazy list. a/<! just wouldn't work there. There are some limits on a/<! that I don't quite recall, but IIRC they're explicit - if it won't work in some context within a/go, then the compiler will yell at you. For now, try using a/go-loop or mapv instead.