This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-29
Channels
- # announcements (1)
- # babashka (1)
- # beginners (46)
- # calva (2)
- # cider (6)
- # circleci (10)
- # clj-kondo (2)
- # cljsrn (2)
- # clojure (30)
- # clojure-dev (6)
- # clojuredesign-podcast (8)
- # clojurescript (28)
- # conjure (1)
- # core-logic (2)
- # core-matrix (2)
- # cryogen (16)
- # figwheel-main (2)
- # graalvm (4)
- # jobs (1)
- # malli (15)
- # minimallist (1)
- # off-topic (70)
- # pathom (4)
- # reagent (3)
- # releases (2)
- # remote-jobs (8)
- # rewrite-clj (3)
- # shadow-cljs (4)
- # tools-deps (29)
- # uncomplicate (3)
REPL driven development question… When I want to test a line in a function that depends on an argument without calling the function, what do you do to provide a value for the argument? Do you just throw in a ‘def’ or is there a better way?
What I often do is pull the line out of the function, and execute it in the repl, wrapped in a let
@UBMFBEWKY Put a (comment ,,,)
form immediately after the function. Then put (def addend 4)
inside that comment and evaluate the def
, then you can eval any form inside the function.
That way you're not modifying the "production code", but your scratch code stays visible and available in your code for future use.
And maybe attend one of my online talks in December/January https://corfield.org/blog/2020/11/24/talks-clojures-superpower/ 🙂
Thanks! I know it’s a bit of a silly question but I figured there was a common way.
I like the (comment …)
version.
"Rich Comment Form"
(because Rich Hickey does this too)
(and definitely not a "silly question" -- getting to a really efficient RDD workflow is something that a lot of people struggle with, because it's not like how you work with other languages)
also, with code that exists already, it's often useful to insert a tap>
call into the defn
, then use an add-tap
function that captures values for experimentation
this is my "stethascope" for examining internals of a running system with legacy code
I haven’t ventured into debugging running/deployed code. Tap is new to me, I’ll read about it. Maybe @U04V70XH6 will cover such wizardry in his upcoming talks? Thanks for the suggestion.
@UBMFBEWKY I will make sure I cover that (since I use Reveal alongside my editor to show all tap>
'd values).
How can fix the error:
clojure -M:uberjar
Compiling yubrshen.unique-errors ...
Compilation of yubrshen.unique-errors failed!
Could not locate yubrshen/unique_errors__init.class, yubrshen/unique_errors.clj or yubrshen/unique_errors.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
I'm use an app template from: https://github.com/seancorfield/clj-new
Here is the related alias for :uberjar:
:uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.1.128"}}
:main-opts ["-m" "hf.depstar.uberjar" "unique_errors.jar"
"-C" "-m" "yubrshen.unique-errors"]}
It seems that I may need somehow to install unique_errors.jar?
Thanks!What are the file/folder names used? It looks like a classpath error. Your namespace yubrshen.unique-errors
includes a dash which is okay, but your filenames should uses underscores, replacing the dashes.
@brianbadahdah thanks for helping! yubrshen.unique-errors namespace is not of my own, it's prescribed by the alias of :uberjar, which is generated by clj-new template for app. My own namespace is just yubrshen.friendwall The error happened when I created the jar file for friendwall.jar (I don't even know the purpose of yurbrshen.unique-errors) Should I implement somehow <project-parant-folder>/friendwall/yubrshen/unique_errors.clj ?
Sorry, the error is caused by my mistake! unique_error was an old project of mine, that I forgot to change it to the new project frendwall, when I copy and paste the deps.edn
Hello everyone, is there a way to get the query result without the brackets?
(d/q '[:find (pull ?e [:commit/rev])
:in $ $date
:where
[?e :commit/date ?date]
[(> ?date $date)]]
@conn date)
;; => ([#:commit{:rev "25ed6cb"}]
;; [#:commit{:rev "02a760a"}]
;; [#:commit{:rev "61df934"}]
;; [#:commit{:rev "d6524ab"}])
Like this but without the extra step.
(->> result
(reduce (fn [acc e] (conj acc (first e))) '()))
;; => (#:commit{:rev "4e2cce7"}
#:commit{:rev "13c57d1"}
#:commit{:rev "8a3fd52"})
@lukas.block you can try doing this if it helps:
(map first result)
;; or
(->> result
(map first))
hey thank you. The reduce was just an, I have to admit overly complicated example, for an extra step
@brianbadahdah thanks for helping! yubrshen.unique-errors namespace is not of my own, it's prescribed by the alias of :uberjar, which is generated by clj-new template for app. My own namespace is just yubrshen.friendwall The error happened when I created the jar file for friendwall.jar (I don't even know the purpose of yurbrshen.unique-errors) Should I implement somehow <project-parant-folder>/friendwall/yubrshen/unique_errors.clj ?
What is a good tool to ‘make 150 http requests (random order) with N workers’ ? Should I reach out to java.util.concurrent?
Sorry, the error is caused by my mistake! unique_error was an old project of mine, that I forgot to change it to the new project frendwall, when I copy and paste the deps.edn
Going to do now with what I am familiar with .. java.util.concurrent.ExecutorService
but I am interested in learning more about clojure.async
which also seems to be able to do this
Client libraries like httpkit allow you to pass an optional thread pool (number of workers). You can then use core.async's async-pipeline to control the number of inflight requests
I need to investigate that. Right now I have a simpler approach:
(defn ping-endpoints [endpoints]
(let [pool (Executors/newFixedThreadPool 8)
tasks (for [url endpoints] #(ping-endpoint url))
futures (.invokeAll pool tasks)]
(for [f futures] (.get f))))
Beware that for is lazy. Laziness and side effects don't mix well together. I recommend either coercing it via doall or using mapv. Also take a look at https://github.com/TheClimateCorporation/claypoole
You don't care if your data disappears when the power goes off?
I believe quite a few databases are good at keeping recently used data cached in RAM.
Sorry - what I mean is that I wish I could just Clojure data structures and not bother with SQL at all
Anyway, am doing qn 39 have a solution to make my own version of interleave but is there a way I can remove vector
? Like by changing concat
to something else?
(defn leave [a b]
(when (and (not-empty a) (not-empty b))
(concat (vector (first a)) (vector (first b))
(leave (rest a) (rest b)))))
yeap list
works too but was wondering if there's a concat that doesn't require elements to be in some form of collection
Also does anyone understand why mapcat vector
works as a replacement for interleave
?