This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-06
Channels
- # aleph (1)
- # announcements (3)
- # asami (32)
- # aws (12)
- # babashka (6)
- # beginners (43)
- # calva (36)
- # cider (3)
- # clj-kondo (3)
- # cljs-dev (2)
- # clojars (6)
- # clojure (66)
- # clojure-europe (14)
- # clojure-uk (2)
- # clojurescript (12)
- # conjure (1)
- # core-async (27)
- # cursive (17)
- # data-science (9)
- # datahike (1)
- # datomic (28)
- # emacs (34)
- # events (1)
- # girouette (3)
- # jobs (1)
- # klipse (4)
- # lsp (26)
- # malli (5)
- # off-topic (38)
- # portal (1)
- # releases (1)
- # shadow-cljs (72)
- # sql (7)
- # tools-deps (5)
- # vim (9)
- # xtdb (18)
(.toInstant #inst "2022-04-15")
I like Instant because of the isBefore
method. And I like to type in year month day somehowregarding isBefore
, there's also the polymorphic compare
function
(ins)user=> (compare #inst "2022-04-15" #inst "2022-07-21")
-1
I am looking at some of the code in the Clojure Cookbook and this sample on I/O
(ns keystroke.core
(:import [jline.console ConsoleReader]))
(defn show-keystroke []
(print "Enter a keystroke: ")
(flush)
(let [cr (ConsoleReader.)
keyint (.readCharacter cr)]
(println (format "Got %d ('%c')!" keyint (char keyint)))))
Sorry bad at entering code in Slack, anyways it requires using lein trampoline to run in the REPL and I am wondering what the equivalent for lein trampoline is when using the Clojure CLI deps tooling?
leiningen starts two jvm instances: one for your code and one for leiningen itself. lein trampoline
will exit the second jvm instance once the jvm for you code is ready.
clojure cli runs only one jvm instance so there is no equivalent of lein trampoline. just start repl normaly
I am using CIDER and still I see that when I run show-keystroke from the REPL it hangs, is there something different about the nREPL in CIDER?
/tmp/ex via ā v17.0.3
āÆ clj
DEPRECATED: Libs must be qualified, change jline => jline/jline (deps.edn)
Clojure 1.11.1
user=> (import '[jline.console ConsoleReader])
jline.console.ConsoleReader
user=>
user=> (defn show-keystroke []
(print "Enter a keystroke: ")
(flush)
(let [cr (ConsoleReader.)
keyint (.readCharacter cr)]
(println (format "Got %d ('%c')!" keyint (char keyint)))))
#'user/show-keystroke
user=> (show-keystroke)
Enter a keystroke: Got 113 ('q')!
nil
it works when you start repl from the shellno, but it might confuse some editors. For example in emacs cider-eval-last-sexp evals next sexp instead of previous:
(defn foo [])
^L
;; cursor is hear but and last sexp is ^
;; but my emacs evals the one below
(defn bar [])
I'm actually using them to take advantage of backward-
and forward-page
.
That's interesting. And using C-x C-e
instead of C-c C-c
evaluates the first form. So you can choose which one you want to be eval'ed.
Is there some reason data files in a folder on the classpath would affect REPL startup times? I had a few large CSV files in a resources/data
folder in my project and it was taking nearly 90 seconds to start a REPL, after removing them it drops back to 15-20 seconds. I can understand why it would impact something like uberjar creation, but I don't have an intuition for why clojure/java is reading those files during startup.
normally no, but maybe a namespace or class you're loading is scanning for and reading those files?
if you catch it during the slow load, you might see a thread (probably "main") with a culprit trace
if you do catch a library/tooling doing that, it is likely a bug, because resources/ is stuff that should be loadable via a classloader, which doesn't allow for scanning
Thanks, I think I found it. It's a kit-clj project which seems to use lambaisland/classpath
to monitor for deps changes and that ultimately uses https://github.com/gmethvin/directory-watcher which hashes all the files it's monitoring. Removing the watch-deps
call from my user.clj
stops the CSV files from being read
it still seems like a bug though because the docs seem to indicate it only watches the deps.edn file, not everything in the classpath
I have a map, and I want to conj something into a key that might not exist, this works:
(let [vm {}]
(update vm :output conj 5))
;=> {:output (5)}
But I get a list out, is their a way to make it a vector ?Is there an idiomatic way to randomly pick 1 item from a set? I want a set version of this:
(loop [some-list (whatever ...)
results '()]
(if (empty? some-list)
results
(recur (rest some-list)
(conj results (calculate-something (first some-list))))))
Obviously first and rest don't work on set.
What might I use instead?Why does it need to be a set ? If you just want to start with a collection, then randomly take items and do stuff, you could shuffle it first, then just map over it ? Something like:
(let [xs (shuffle (range 100))]
(map (fn calc-something [n] n) xs))
?It needs to be a set because I need to perform set operations. Right now my algorithm takes a list and converts it to a set to do unions, intersections, etc. Converting lists to sets and sets to lists is killing performance. Then I realized if I could just operate on sets the performance problems would go away.
i don't think there is a lot of performance difference between doing set -> seq -> set instead of just set -> set.
first does work on sets, is suppose by converting to a seq, but i don't think it is much slower. Instead of rest you can remove the element from the set with disj.
(loop [some-set (whatever ...)
results '()]
(if (empty? some-set)
results
(recur (disj some-set (first some-set))
(conj results (calculate-something (first some-set)))))
but they're not random
Oh cool
It's fine if they're not random
I feel silly for not trying that out. The name "first" implies order, and sets don't have order, so I assumed first would not work on a set. Same for rest.
sets (all Clojure colls really) are seqable, that is they can provide a logical list view of the data
and seq functions (like first, rest, etc) always get a seqable view before doing the operation