This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-01
Channels
- # announcements (3)
- # babashka (1)
- # beginners (29)
- # calva (3)
- # cider (5)
- # clojure (17)
- # clojure-europe (9)
- # clojurescript (31)
- # conjure (2)
- # cursive (14)
- # datomic (51)
- # deps-new (4)
- # honeysql (8)
- # introduce-yourself (1)
- # lumo (8)
- # malli (28)
- # missionary (1)
- # off-topic (20)
- # pathom (2)
- # polylith (22)
- # practicalli (10)
- # reagent (3)
- # reitit (6)
- # ring (2)
- # schema (2)
- # shadow-cljs (25)
- # spacemacs (3)
Are there any real performance difference between inline and external protocol implementations?
How to choose which one to use if you can change the type? From “Clojure Programming” I understood that the main benefit of inline implementation is the performance, and probably should use extend*
— while I mostly see defrecord
/ deftype
(I guess)
Not sure i did the right thing on measuring performance, but :
(defprotocol Noop
(dont-do [this]))
(defrecord InlineNoop []
Noop
(dont-do [_] nil))
(def inline-op (->InlineNoop))
(criterium.core/quick-bench
(dont-do inline-op)) ;; ==> Execution time mean : 2.100368 ns
(extend-type String
Noop
(dont-do [_] nil))
(criterium.core/quick-bench
(dont-do "asd")) ;; ==> Execution time mean : 2.118537 ns
> Thus, inline implementations, while tempting because they appear so familiar (methods > in classes!), are more static than other protocol extension mechanisms, and are best > kept as an optimizing step. (Clojure Programming)
Hello! May I know what are good ways to debug clojurescript in production/in a docker?
Also if I compile my code into a jar, and I have the code (shell/sh "python3" "resources/test.py" "10")
how do I make sure my program refers to the "resources" folder in my jar ?
Otherwise I am using lein and the resources folder is already being added to the jar it produces
@deleted-user seems like .getPath
doesn't really work in the case of a jar Caused by: java.io.FileNotFoundException: /home/zackteo/Documents/Capstone/Clojure/URA-Capstone-Frontend/deploy/ura-site-search-0.1.0-SNAPSHOT-standalone.jar!/Single-Objective-Models/Generalised_v2_final.py (No such file or directory)
I meet a problem when trying lein test
the error is Caused by: java.lang.ClassNotFoundException: clojure.set
and in the file, it is written
(def solution-10
(loop [nums (set (cons 2 (range 3 2000000 2)))
n 3]
(if (> (* n n) 2000000) (reduce + nums)
;; else
(recur (clojure.set/difference nums (range (* n n) 2000000 n))
(+ n 2)))))
what the fuck? I can run it on repl, but I faild in test ??namespaces can be preloaded by a repl that aren't loaded in a regular process, no clojure namespace other than clojure.core is guaranteed to be loaded before you require it
@steiner3044 is it possible that you imported clojure.set
in your repl already but its not available from your testrunner?
In the REPL: (require '[clojure.set])
In a namespace form:
(ns xyz
(:require [clojure.set]))
just add a require to it in your namespace. (ns the-ns (:require [clojure.set :as set]))
and then use set/difference
I was suddenly confused, again, trying to use Reveal with Atom/Chlorine. Reveal eats prepl, Chlorine wants socket repl. Probably a thousand ways to wire it up anyway, but I’m not fluent in repls enough to improvise. Help or pointers much appreciated, general or specific to my situation 🙂
How can I run tests that depend on genclass
-shenanigans in a deps.edn + build.clj based project?
@wordempire You need to run the compile step, then run your tests: tools.build
is not intended as a test runner (although we've made that work by using java-command
and process
to run tests as a subprocess).
I already have my test-runner set up under a deps.edn alias; I currently have to run run my tools.build compile command, and then run the test runner; what exactly are you suggesting here? Having some tools.build step call out to my test runner alias using java-command or process?
"I currently have to run run my tools.build compile command, and then run the test runner" -- that is the expected workflow.
But at work, we've used create-basis
, java-command
, and process
to run tests from build.clj
. It's non-trivial but possible.
If you normally run tests via -M:test
, the you'd create-basis
with {:aliases [:test]}
and pass the basis to java-command
along with a vector of command arguments, like :main-opts
plus whatever else you'd provide on the command-line, and then you pass the result of that into process
. I should write up an example of it on my blog -- or incorporate it into one of my OSS projects so folks can see how it is done.
Like so:
(! 1672)-> head deps.edn
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
org.clojure/java.data {:mvn/version "1.0.86"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.2"}}
:aliases
{:build {:deps {io.github.clojure/tools.build {:git/tag "v0.1.7" :git/sha "8a3abc2"}}
:ns-default build}
:test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
...
(! 1673)-> cat build.clj
(ns build
(:require [clojure.tools.build.api :as b]))
(defn run-tests
[_]
(let [basis (b/create-basis {:aliases [:test]})
cmds (b/java-command {:basis basis
:main 'clojure.main
:main-args ["-m" "cognitect.test-runner"]})]
(b/process cmds)))
(! 1674)-> clojure -T:build run-tests
You can see the whole deps.edn
here: https://github.com/seancorfield/next-jdbc (for the rest of the :test
alias that has the Cognitect test-runner
in it.
Thank you! This was pretty much what I was looking for (and not understanding) until you clearly laid it out here.