This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-22
Channels
- # aleph (5)
- # announcements (9)
- # babashka (9)
- # beginners (127)
- # cherry (1)
- # cider (48)
- # clj-kondo (5)
- # cljdoc (1)
- # clojure (70)
- # clojure-berlin (1)
- # clojure-europe (57)
- # clojure-france (2)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (2)
- # css (1)
- # cursive (6)
- # emacs (6)
- # gratitude (1)
- # honeysql (5)
- # introduce-yourself (5)
- # jobs-discuss (7)
- # joyride (1)
- # kaocha (3)
- # lsp (1)
- # malli (9)
- # nbb (2)
- # off-topic (91)
- # pathom (7)
- # pedestal (14)
- # re-frame (4)
- # reitit (67)
- # shadow-cljs (46)
- # spacemacs (3)
- # squint (3)
- # tools-build (14)
- # tools-deps (1)
- # vim (3)
If I'm running this command
java -cp `clj -Spath` clojure.examples.hello Fred
(with my own compiled clj code of course) what do I have to do to make it work on Powershell? Besides not using Powershell, which I wish was an option here.I tried different quoting around "clj -Spath" and I get various errors
https://stackoverflow.com/questions/44281699/bash-batch-like-subshell-in-powershell#44281958
Thank you @U0NCTKEV8!!
For those that use Malli. Is there any equivalent of :enum
for maps? E.g. I want to do this:
(def conj-auth
[:map
{:closed true}
email
pass])
(def google-auth
[:map
{:closed true}
provider
code])
(def auth
[:enum
conj-auth
google-auth])
Anyone else feeling the need for a schemas algebra? An ability to push a merge of a map schema into and, or, multi, etc
Commutative schemas? Schema multiplication? Schema matrices? sin(schema)? 😄 But yes, currently I merge my schema "by hand" with my hardcoded defaults :thinking_face:
Is there a way to know if code is evaluated during compilation or during runtime?
Maybe like this. I interpret your runtime as "non top level".
(ns handler)
(prn :file *file*)
(defn foo []
(prn :file *file*))
(defmacro bar []
(prn :file *file* )
`(prn :file *file*))
(bar) ;; compile time :file
(defn baz []
;; compile time file and runtime file
(bar))
(defn -main [& _args]
(foo)
(baz))
$ clj -Scp $(clojure -Spath):/tmp -M -m handler
:file "handler.clj"
:file "handler.clj"
:file "handler.clj"
:file "handler.clj"
:file "NO_SOURCE_PATH"
:file "NO_SOURCE_PATH"
So when it's executed non-top-level, :file is NO_SOURCE_PATHYou can add a println
or spit
anywhere in your code to see if something is being evaluated
e.g.
(ns my-namespace)
(println "hello")
(spit "abc.txt" "evaluated")
(defn test[] (println "hello2"))
thanks!
Is there a way to take a protocol's methodImplCache implementation and carry it around? I don't want a full on protocol, just a cached implementation for types
Plumatic Schema recently added a s/defprotocol that does stuff with methodImplCache - worth checking out?
I'll look, but having peeked a bit into the core implementation I have an educated guess what it's doing
Guys, I have reached the limit in my knowledge regarding dependencies, I switched to clojure 1.11.1, and I keep getting this error
[{:type clojure.lang.Compiler$CompilerException
:message Unexpected error macroexpanding go at (datomic/client/impl/shared.clj:99:5).
:data {:clojure.error/phase :macroexpansion, :clojure.error/line 99, :clojure.error/column 5, :clojure.error/source datomic/client/impl/shared.clj, :clojure.error/symbol go}
:at [clojure.lang.Compiler macroexpand1 Compiler.java 7036]}
{:type java.lang.NoSuchFieldError
:message __thunk__0__
:at [clojure.tools.analyzer.jvm.utils__init load nil 259]}]
any ideas on why this keeps happening?
sound similar to this - https://clojurians.slack.com/archives/C03S1KBA2/p1669021808743179
Some tips for debugging this kind of thing:
• Try undoing your change to be sure that it really is clojure depdency change that caused the issue.
• Make sure you have cleaned the target directory (e.g. with lein use lein clean
)
• Try compiling the code outside of REPL (e.g. with lein use lein check
)
• Compare the full dependency graph before + after your change (e.g. with lein run lein deps :tree
)
• Try eliminating a bunch of your code + dependencies until the error goes away. Then add them back slowly to see was causing the issue.
• It's possible that the bug is a dependency conflict
@UJVEQPAKS I have done just that
it seems that the problem is core.async related
if I rollback to the older version everything works perfectly
@U9BQ06G6T Search for __thunk__0__
here on slack, it has been reported before this week
Yes, @U04V4KLKC has pointed me to that topic, I have checked the aot compilation of the suggested namespace, but either I am doing something wrong (which shouldn’t be to far from the truth) or the solution doesn’t work for me
Thanks everyone for your input
why are clojure bindings evaluated in parallel? (binding [a ... b ...])
sorry, "made"
The new bindings
are made in parallel (unlike let); all init-exprs are evaluated
before the vars are bound to their new values.
Not sure, but it's trivial to nest them if you don't want that behaviour
(binding [a 1] (binding [b 2] ...))
I agree that it's odd that they follow a different convention to let
. I'm not sure which convention is more proper. It might just have been arbitrarily easier to do it this way when they wrote the code for it.
> why are clojure bindings evaluated in parallel? (binding [a ... b ...])
I'd say it's because it's implemented in terms of with-bindings
which accepts a hashmap (i.e. unordered semantics)
...of course one API doesn't have to be coupled to the other. my wild guess is that they initially were, then it was a little too late to fix it?
yeah i'm about to write a bindings2 macro to de-pyramid a set of bindings
I think making it like let
would be completely backwards compatible (but not the other way around).
yeah it seems just lazy / good enough impl
however it's a reasonable concern to not invite people to write code in clojure 1.N that would not correctly work in clojure 1.(N - 1)
user=> (binding [*a* 10
*b* (+ *a* 1)]
(+ *a* *b*))
12
user=> (binding [*a* 10]
(binding [*b* (+ *a* 1)]
(+ *a* *b*)))
21
>
all init-exprs are evaluated
> before the vars are bound to their new values.
>
is the important part right?in my second example, like let, it uses the newly bound value of *a*
(1) rather than the before-all-bindings value of *a*
(10)
yes you're right
Oops - was thinking about the case where the binding didn't exist already.
that condition doesn’t exist here > Creates new bindings for the (already-existing) vars
ie was thinking of
(binding [*a* 10
*b* (+ *a* 1)] ;;<-- Null pointer exception a is nil (not yet bound)
(+ *a* *b*))
Would be odd for someone to be relying on this
user=> (binding [*a* 10
*b* (+ *a* 1)]
(+ *a* *b*))
12
that’s the docstring described behavior right? Wouldn’t it be odd to rely on behavior contrary to the indicated behavior?
I agree that they can rely on it since the docstring says that. I just expect it's probably very rare case in the wild (given your + my illustrations above). So it would technically be a breaking change but breaking very little.
For me, I don't think the change is required though since I don't think we want to make binding particularly more common.
we’re just using numbers. but lots of printing stuff uses this. from nrepl:
(binding [*print-readably* true
*print-length* nil
*print-level* nil]
(doto out
(.write (str %))
(.flush)))
the fact that these all would reference the current binding could be very important and changing the behavior could radically alter how Clojure printsI have a magic the gathering-like card game, and I have the card definitions separated by type, but we're coming up on 4k+ lines in each of these card files (and 6k+ lines in the associated test files), which is a little unwieldy. I'm considering breaking these files into multiple files, one definition per file. in javascript, it's easy to loop over a directory and require
each file which will perform some side effect (adding an entry to a map). are there any common idioms for that in Clojure?
(def data1 (delay (edn/read-string (io/resource "foo/bar.edn"))))
I use this a lot in testsSadly, these are a lot of data but they have a lot of code too (`defcard` is a macro, for example)
(defcard "Underway Grid"
{:events [{:event :pre-expose
:req (req (same-server? card target))
:msg "prevent 1 card from being exposed"
:effect (req (expose-prevent 1))}]
:constant-effects [{:type :bypass-ice
:req (req (same-server? card target))
:value false}]})
oh yeah, i forgot about those. interesting, maybe I can use that
Thank you, that's great
To follow up on this, when is it better to use in-ns
vs ns
? Given that calling ns
multiple times on the same namespace is additive, seems like there's no reason except semantic clarity to use in-ns
my preference is to use ns
to define namespaces and in-ns
to switch to a namespace programatically. Seeing multiple ns
forms for the same ns would be strange to me (and might confuse tooling)
We have a certain (Thread/sleep)
in our codebase, and nothing from our own side that would intentionally interrupt it.
However in our production logs I'm seeing an InterruptedException
with the familiar "sleep interrupted"
message.
I have no idea of what could be interrupting this thread. Are there some usual suspects? Is it something that a web server could be doing?
(I'll grep for that)
Or is it something that is implied with JVM shutdown perhaps?
Other ideas welcome.
user=> (.interrupt (Thread/currentThread))
nil
user=> (Thread/sleep 100)
Execution error (InterruptedException) at java.lang.Thread/sleep (Thread.java:-2).
sleep interrupted
user=>