I'm a bit confused with the following:
(:require [ring.adapter.jetty :as jetty]
[ring.util.response :as response]
[ring.middleware.reload :refer [wrap-reload]]))
(defn handler [request]
(str "<html><body> your IP is: "
(defn wrap-nocache [handler]
(assoc-in [:headers "Pragma"] "no-cache"))))
(defn -main 
(-> handler var wrap-nocache wrap-reload)
censor-wordfunc works fine, and
playis updated in
play-with-wordonly outputs all-censored word and game never ends.
@YuriMostardeiro Hey. You're asking two questions here:
atomand not a
@fileA/myDef. Or maybe don't use an atom at all, if you don't need to change its value
reversebefore you reduce it: https://clojuredocs.org/clojure.core/reverse
Hi everyone, I'm new to clojure, appreciate if you can point out how shall I implement this
I want to format byte size into human-friendly format.
But I feel
reduce isn't the right approach if the list is huge (I call
format-size on a large list), is there a way to early return (without using exception) ?
One approach I can think of is to use recursive function with, so I can stop iteration, but then I'll have to urgly decompose in each loop, like
(first c) and (first (rest c))
@beenotung There's no need for iteration at all. If you prepend an empty string to the vector of units, the index of that vector becomes a corresponding power of 1024 that corresponds to that unit (1024^0 - no unit, 1024^1 - KB, and so on).
So, you need to just get the logarithm of the input number to the base of 1024, round it down, and get the unit from the units vector.
Of course, you can still use iteration to actually find the logarithm. Or you could use the built-in math function.
On a side note - you can stop a reduction early by using
set!the var created by a
defat the NS scope or you can use a dynamic variable if that makes sense. More details: https://clojure.org/reference/vars
metabase.util/prog1macro which defines that symbol: https://github.com/metabase/metabase/blob/master/src/metabase/util.clj#L173