Fork me on GitHub
#clojure
<
2017-01-08
>
qqq00:01:04

(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 ?

qqq00:01:17

^^ this is using bidi

qqq00:01:42

make-handler is bidi.ring/make-handler

joshjones01:01:51

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

qqq01:01:01

(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

joshjones01:01:35

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?

joshjones01:01:48

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

joshjones01:01:48

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

qqq02:01:24

(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
             Compiler.java: 6978  clojure.lang.Compiler/eval
             Compiler.java: 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
               RestFn.java:  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
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  657  clojure.core/apply
                  core.clj: 1963  clojure.core/with-bindings*
any idea how to fix this?

qqq03:01:26

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

qqq06:01:49

https://khinsen.wordpress.com/2012/03/15/python-becomes-a-platform/ <-- this blog post talks about clojure-py // is this effort still active, or has it been killed?

qqq07:01:39

@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

beppu09:01:46

@tbaldridge (aka halgari) ^^

tbaldridge18:01:34

@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

qqq19:01:03

@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

qqq20:01:08

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

sveri21:01:16

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

sophiago23:01:59

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

williewillus23:01:28

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

http://steve.hollasch.net/cgindex/coding/ieeefloat.html <-- given the layout of sign, fraction, exponent; what does it even mean to "bit shift" a float?

sophiago23:01:55

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

sophiago23:01:02

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

qqq23:01:18

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

qqq23:01:40

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