Fork me on GitHub

(def core-app
  (make-handler ["/" {"" (redirect "/public/index_prod.html")
                      "index.html" index-handler
                      ["articles/" :id "/article.html"] article-handler}]))
localhost:8080/index.html works localhost:8080/articles/232/article.html works localhost:8080/ does not work -- what am I doing wrong ?


^^ this is using bidi


make-handler is bidi.ring/make-handler


I don't know bidi but I would check to ensure that index-handler and article-handler return the same data shape that (redirect ...) does. @qqq


(defn index-handler [request]
  (res/response "Homepage"))

(defn article-handler [{:keys [route-params]}]
  (res/response (str "You are viewing article: " (:id route-params))))

res is ring.util.response @joshjones


and does the output of those two functions match that of (redirect ...) ? I guess (redirect ...) returns a map? Does the make-handler function allow you to give it a route to match (`""` in your case) and then something that is (probably not) a handler function?


i guess you replaced the call to redirect with index-handler to see whether it is even matching "" correctly?


actually, I just looked at the source and it appears you can use redirect this way as it returns a handler


(defn handle-request [& rest]
    (println "handle-request: " rest)
    (ring.util.response/response "Hello world"))

  (def routing-table
    ["/" {"" :root
          "index.html" :index}])

  (def core-app
    (bidi.ring/make-handler routing-table handle-request))
  (let [r (ring.mock.request/request :get "/")]
    (core-app r))
^^^ this gives me
1. Unhandled java.lang.IllegalArgumentException
   No implementation of method: :request of protocol: #'bidi.ring/Ring
   found for class: clojure.lang.PersistentArrayMap

          core_deftype.clj:  583  clojure.core/-cache-protocol-fn
          core_deftype.clj:  575  clojure.core/-cache-protocol-fn
                  ring.clj:   12  bidi.ring/eval48095/fn/G
                  ring.clj:   37  bidi.ring/make-handler/fn
                      REPL:  110  g.apps.index/eval52126
                      REPL:  109  g.apps.index/eval52126
    6978  clojure.lang.Compiler/eval
    6941  clojure.lang.Compiler/eval
                  core.clj: 3187  clojure.core/eval
                  core.clj: 3183  clojure.core/eval
                  main.clj:  242  clojure.main/repl/read-eval-print/fn
                  main.clj:  242  clojure.main/repl/read-eval-print
                  main.clj:  260  clojure.main/repl/fn
                  main.clj:  260  clojure.main/repl
                  main.clj:  176  clojure.main/repl
       137  clojure.lang.RestFn/applyTo
                  core.clj:  657  clojure.core/apply
                  core.clj:  652  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
      1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87
          152  clojure.lang.AFn/applyToHelper
          144  clojure.lang.AFn/applyTo
                  core.clj:  657  clojure.core/apply
                  core.clj: 1963  clojure.core/with-bindings*
any idea how to fix this?


figured it out, handle-request needs to return a function

qqq06:01:49 <-- this blog post talks about clojure-py // is this effort still active, or has it been killed?


@beppu: yes, but on Google there are other results for clojure-py, and (2) halgari is in this channel, so I was hoping to get insights from him


@tbaldridge (aka halgari) ^^


@qqq the original Clojure-Py had some glaring issues. I have nothing currently to replace it with, but rewriting it is something I would like to do at some point


@tbaldridge: can I DM you about clojure-py / clojurescript-py? I'm writing a lot of numpy/tensorflow lately, completely miss the terseness of clojure + power of macros, and want to get your thoughts on potential challenges of cljX -> py


When using clj on server and cljs on client side, is there ever any reason to pick json over edn? [This API doesn't have to work with other services; it only needs to work with my app.]


@qqq I dont know any. Also, have a look at transit. there is a transit wring middleware and cljs-ajax picks transit as default format.


how would i go about bit-shifting a float in clojure? i figured something like (unsigned-bit-shift-right (byte 1.0) 1) but it's rounds down to zero instead of returning 0.5


I don't think the shift operators are defined on floating point types on the jvm, you would have to get the raw bits using Float/floatToIntBits then shift that, then use Float/intBitsToFloat to turn it back into a float

qqq23:01:12 <-- given the layout of sign, fraction, exponent; what does it even mean to "bit shift" a float?


@williewillus ah, thanks! i think that's just what i was looking for, but only could find Integer/toBinaryString. lemme give it a shot


@qqq same as an int except you're shifting the mantissa


that's not the same as "bit shifting the bits of the float"


don't you just want * 2 or / 2?