This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-22
Channels
- # adventofcode (37)
- # beginners (74)
- # boot (2)
- # boot-dev (31)
- # cider (88)
- # clara (109)
- # cljs-dev (63)
- # clojure (96)
- # clojure-argentina (1)
- # clojure-czech (1)
- # clojure-dusseldorf (2)
- # clojure-france (2)
- # clojure-germany (3)
- # clojure-greece (2)
- # clojure-italy (5)
- # clojure-norway (1)
- # clojure-spain (1)
- # clojure-spec (25)
- # clojure-uk (46)
- # clojurescript (26)
- # cursive (19)
- # data-science (5)
- # docs (2)
- # duct (18)
- # editors (2)
- # emacs (3)
- # figwheel (2)
- # fulcro (29)
- # graphql (3)
- # hoplon (143)
- # juxt (7)
- # klipse (1)
- # leiningen (5)
- # lumo (1)
- # monads (1)
- # off-topic (23)
- # onyx (49)
- # powderkeg (6)
- # re-frame (4)
- # reagent (8)
- # ring (3)
- # shadow-cljs (24)
- # specter (70)
- # sql (1)
- # unrepl (96)
- # yada (3)
yeah, profiling with actual runtime conditions is always called for if there are performance problems
speculatively optimizing before you have something that works is a great way to waste a lot of energy
It just occurred to me... we should update our multi-version testing to check code against clojure-1.10.0-master-SNAPSHOT
now that 1.9 is released! š
When using pprint
on a map containing namespaced keywords, long namespace prefixes are kind of a headache, pushing the output far to the right. Is there a way (short of writing my own formatter) of having it substitute aliases for the full namespace name?
(set! *print-namespace-maps* false)
perhaps?
(not sure how you'd get an alias substituted in -- unless you wrote your own print-method
for clojure.lang.IPersistentMap
?)
*print-namespace-maps*
is a little better, though it sort of shifts the readability problem. I guess I'll think on making a custom print-method
that interrogates the current ns aliases or something.
Is there a builtin for:
(defn u-in [obj path f]
(let [o (get-in obj path)
[nv & rst] (f o)]
(into [(assoc-in obj path nv)] rst)))
(u-in {:a {:b 2}
:foo :cat} [:a :b] (fn [x] [(inc x) :foo]))
is there a better way to write:
(fn [[o f]] (f o))
it seems like a weird enough function there should be some weird name for itis there a 'stateful iterate' ? i.e. suppose (f x0) = [x1, v1] (f x1) = [x2, v2] (f x2) = [x3, v3] .... I want something where (g x0 3) = [x3, [v1 v2 v3])
(def fapp (fn [[f & args]] (apply f args))) <-- wtf, is this function just #(apply apply %) ?
woah clojure is just incredible, there are plenty of different macros and then you think āsuper handy - if there was only a way do slightly diverge from the default behaviorā, and then you google a bit and there is for sure something build in š
https://clojurians.slack.com/archives/C03S1KBA2/p1513940248000267
(map second (iterate f x0))
ah, didnāt notice you want all the v
s
(->> [0 []]
(iterate (fn [[x vs]]
(let [[x' v'] (f x)]
[x' (conj vs v')])))
next
(take 3))
@cgrand Thanks!
Who said that Clojure's long startup time can't be fixed? š See https://stackoverflow.com/questions/19107683/speed-up-clojure-startup-time-with-nailgun
>In my case, startup time of the actual script went down to 80ms
:repl-options :init-ns
so, in project.clj, you could add: :repl-options {:init-ns user :port 4001 :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
itās a little cumbersome but you could do
clj -e "(use 'clojure.set) (in-ns 'clojure.set)" -r
my favorite golfing of require / switch ns is (doto 'clojure.set require in-ns)
What would you call the value that peek
returns? You can't call it "first" or "last" since that depends on the type you supply.
not only that but first and last are functions you probably don't want to shadow
for a stack, it would be the top value
That's true. Doesn't really matter what the type of the structure is because chances are good you're using it as a stack or queue if you're using pop
and peek
.
I needed an appropriate name for this convenience function I just wrote:
(defn update-top [coll fun & args]
(conj (pop coll) (apply fun (peek coll) args)))
does anyone know how to write to STDIN from clojure? I'd like to write a string to STDIN so that a process listening to *in*
would be able to consume the string
well one of them is a repl and the other is a server receiving messages across a web socket
AFAIK you need to resort to OS functionality to write to STDIN - it's something I wouldn't expect the jvm to abstract or provide for you
you can't spit to *in*
, that will just throw an exception; beyond the obvious *in*
can be freely rebound, and the binding only has to support reading
to rephrase my question: there is a websocket server running in a repl and I want the msg coming through the socket to be interpreted by the repl as if it was entered from STDIN
you can easily start a repl that listens to a fifo or socket btw
I'd start a repl on a new thread in the same process, and bind *in*
to the input from the socket
STDIN isn't special
and you probably want it's *out*
to send back to the client too, for that matter
clojure has a built in socket repl class, but for a websocket you might need to write your own (also I'm sure you're aware this a security nightmare)
yeah =/ other than an http request, websockets seemed the only way to talk to a remote repl from the browser
right, the problem is that a repl effectively gives root because every single mainstream OS has local root holes that don't require physical access
if you trust everyone who can load the web page to have root, that works out (I'd be very careful about who can visit the page of course)
it would be internal to my company's network, but yes I understand the implication. Are jupyter notebooks with ipython kernels similarly insecure?
I don't know python - but a good indicator would be how hard is it to make a shell call inside the python code... if they can run a system command then it's probably about the same
@alexmiller have a quick question about clojure.java.classpath/classpath-directories
with JDK 9
I got an issue for migratus recently https://github.com/yogthos/migratus/issues/126
and traced it down to the fact that the behavior of classpath-directories
changed when using JDK 9
when I run it with JDK 8 or below I see something like:
(#object[java.io.File 0x30efe7c "/Users/yogthos/src/migratus/test"]
#object[java.io.File 0x70111841 "/Users/yogthos/src/migratus/src"]
#object[java.io.File 0x51ee3ff3 "/Users/yogthos/src/migratus/resources"]
#object[java.io.File 0x24a1e205 "/Users/yogthos/src/migratus/target/classes"])
looks like things break down here:
(map
get-urls
(take-while
identity
(iterate #(.getParent ^ClassLoader %) (clojure.lang.RT/baseLoader))))
=> (nil nil nil nil nil nil)
This does look like a bug, the Base ClassLoader is no longer derived from the URLClassLoader
so this code in clojure.java.classpath
fails:
(defn get-urls
"Returns a sequence of java.net.URL objects used by this
classloader, or nil if the classloader does not sastify the
URLClasspath protocol."
[loader]
(when (satisfies? URLClasspath loader)
(urls loader)))
and looks like there is a JIRA task for this https://dev.clojure.org/jira/browse/CLASSPATH-8
Seems like a bug. Patch welcome...
in the mean time it might be better to throw an unsupported exception in clojure.java.classpath/classpath
when running under java 9
the current behavior of returning nil
masks the problem and makes it difficult to figure out what happened
3 lines of unit test per line of code -- is this within reasonable limits, or is it ridicilous ?
depends on how much logic you like to put on a line I guess
here's an example of code + unit tests:
(do ;; stateful
(def si (fn [f s] (itr #(f (first %)) [s])))
(def sic (fn [f s n] (take (+ n 1) (siter f s))))
(def sics (juxt #(first (last %)) #(map second (rest %))))
(def sis (fn [f s n] (sics (sic f s n))))
(def sfc (fn [f c [o sf] i] (va [id #(c sf %)] (f o i))))
(def smap (fn [f o lst] (reduce #(sfc f conj %1 %2) [o []] lst)))
(def swu (fn [s t f] (if (t s) (recur (f s) t f) s)))
(let [g0 (juxt inc #(* 2 %))
g1 (fn [s i] [(+ s i) (+ (* 10000 s) i)])]
(ct/is (= (sic g0 0 3) [[0] [1 0] [2 2] [3 4]]))
(ct/is (= (sis g0 0 3) [3 [0 2 4]]))
(ct/is (= (smap g1 0 [1 2 3 ]) [6 [1 10002 30003]]))
(ct/is (= (swu 1 #(< % 10) #(+ % 2)) 11))))
while you can create new functions for various combinations of builtins, thereās something to be said for writing most of your code in terms of more common functions
for example, if you us smap
somewhere
to figure out what it does you have to then go and figure out what sfc
does
which means you have to figure out what va
does
and I donāt know what va
does
nothing like a codebase that forces you to master a language only used in Tolkien's Sylmarillion in order to understand it