there is no reliable way to stop a thread (including future-cancel) from another thread, without the thread co-operating (like polling the atom)
maybe using something like https://github.com/TheClimateCorporation/claypoole too
(reliable here being the operative word, future-cancel relies on the interrupted flag being set, the stop methods on threads is deprecated because it is "inherently unsafe")
that use thread pool than you use shutdown for it
shutdown a threadpool generally does not stop the threads if they are actively doing something, it waits for them to stop
but if is this needed in my program? What do you sugest to use?
kill all threads suddenly
Don't write programs that need that
Hi guys, quick qn, as a beginner should I try using kee-frame or use reframe directly? o:
#java-interop Hello, how to invoke default constructor of java class? such as Company(); which is not explicitly defined. thanks.
If the class declares any constructors then it won't get a default constructor, otherwise the default constructor is invokable just like any other
https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8.9
FYI We are starting to host the apropos-clojure
live stream on Discord as of the next episode on Wed 30th Oct 2000 CEST
Here is an invite link that will not expire: https://discord.gg/39DHbU8
We will continue posting the recordings on YouTube for folks that can't or don't want to join live.
I have a question about slack. I get a message like this.
What should I do if I don't want notifications, and don't want it to keep asking me? I don't want to click the button to find out, because that will enable notifications.
You can disable them completely in Preferences
(if you are using the desktop client)
If you're using a browser, there should be an option in your peferences too, in order to disable notifications. I use Firefox and it's in preferences#privacy
is the suggestions to disable all notifications from every tool. or should there be a preference in slack to disable notifications?
So I went into the preferences of slack, and I believe notifications were disabled. because I saw a big green button labeled [Enable Notifications]. I didn't see a button saying disable them. So I assume they were disabled. But to experiment I clicked Enable. Now this is what I see.
I don't want notifications enabled. but there's now no button to undo what I just did. :-(
What does the following error message mean?
expected: (rte-match (quote (:* (or Boolean Long))) [42 43 false])
actual: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
at clojure.lang.RT.seqFrom (RT.java:553)
clojure.lang.RT.seq (RT.java:533)
clojure.core$seq__5387.invokeStatic (core.clj:137)
clojure.core$every_QMARK_.invokeStatic (core.clj:2679)
does it means that it is trying to convert an object whose type is clojure.lang.Symbol
to ISeq? Or does it mean that it actually received the object clojure.lang.Symbol
and cannot convert that? If it means the former, then it would be very nice if it would tell me which object it was trying to convert, so I can have a chance of finding that object in my code somewhere.The problem is that this error seem to be happening in a piece of my error checking code anyway, I'm trying to detect some error condition and report it to the user. But it looks like I'm not doing a good job of detecting the error.
I found the problem and it is very strange. I had a method defined as follows:
(defmethod valid-type? 'or [[_or& others]]
(every? valid-type? others))
I.e., I had forgotten the space before the &
. Strange that nothing else warned me of this.this caused the multi-method framework (or function calling framework) to try to destructure the calling form into [[a b]]
rather than [[a & b]]
. It would be nice if clojure would tell me in this case. Cannot destructure this-data using argument template [[_or& others]]
rather than java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
you'll find unfortunately, for now, error messages are one of Clojure's worst warts / most common complaints, with many errors falling back all the way to very granular activities in the java that makes up the compiler and runtime of Clojure before some sort of exception is emitted, at which case the high level context of the error is often a good bit lost (with the example here being this error finally being triggered with the Clojure runtime tried to convert something invalidly into a seq). Granted, I'm trying to make sure this is the most accurate way to describe said issues
As a fellow Common Lisper, I feel your pain. Clojure is as difficult with errors as CL is amazing. Hang in there, is all I can offer. 🤷
Question about gensym
and macro variables. As I understand there's a trick/idiom in clojure macros to avoid having to use gensym
. Can someone suggest the idiomatic way to eliminate the gensym
in this macro?
(defmacro destructuring-case
"After evaluating the expression (only once) determine whether its return value
conforms to any of the given lambda lists and type restrictions. If so,
bind the variables as if by let, and evaluate the corresponding form."
[expr & triples]
(if (not= 0 (mod (count triples) 3))
(throw (ex-info (cl-format false "destructuring-case expects multiple of 3 number of arguments after the first: not ~A, ~A"
(count triples) (apply list 'destructuring-case expr triples))
{:error-type :invalid-destructuring-case-call-site
:expr expr
:triples triples}))
(let [var (gensym "v")]
(letfn [(conv-1-case-clause [[lambda-list types-map consequence]]
(assert (map? types-map)
(cl-format false "destructuring-case expecting a map, not ~A" types-map))
[(lambda-list-to-rte lambda-list types-map)
`(let [~lambda-list ~var]
~consequence)])]
(let [triples (partition 3 triples)
cases (mapcat conv-1-case-clause triples)]
`(let [~var ~expr]
(rte-case ~var ~@cases (:* :sigma) nil)))))))
I want to concat two maps. https://clojuredocs.org/clojure.core/concat doesn't say whether the first map or the second has priority. At least I didn't see where it explains.
merge
might be a better choice here
oh I see, concat does not give me a map. rather it gives me a sequence with duplication. So I have to convert it into a map
merge might be interesting.
...sanity check 😃
java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long
means that... it's expecting a sequence but got a number?
How can I check if a nested val in an atom is not yet set ?
(empty?) apparently not cool
maybe (not (contains? ... ))
?
Here's the offending lines
(if (empty? (get-in @users-atom [email :streak-count])) ;;fill in a zero for streak count in case one doesn't exist
(swap! users-atom assoc-in [email :streak-count] 0))
but this is not the idiomatic way to ask if a nested value is not-yet-set... how to does?(def a (atom {"<mailto:foo@bar.com|foo@bar.com>" {}}))
(swap! a update-in ["<mailto:foo@bar.com|foo@bar.com>" :streak-count] (fnil inc 0))
thank you
I just want to zero it out in this case... maybe (constantly 0) ?
if you want to set it regardless then (swap! a assoc-in ["<mailto:foo@bar.com|foo@bar.com>" :streak-count] 0)
should work, no?
oh well my problem is actually testing if it is set or not
maybe if (nil? ?^
maybe if (not (number? ...
so if it’s there, do nothing, if it’s not set it to zero?
correct
but i think i could avoid this line completely with (fnil inc 0) !
however for the time being (not (number? )) seems to do the trick.
does it make sense to have :streak-count
set to 0 as default, when you create your user?
Learning to find the relevant part of a full JVM stack trace is a useful skill, although one that appears daunting at first.
The technique of using syntax-quoted expressions that contain symbol names ending in a #
character can often be used to avoid calling gensym
, but there are still macros where that technique does not work, and so gensym
exists.
It appears that your macro has two syntax-quoted expressions, and one of them is intended to be used as a subexpression in the other? If so, then I believe that the symbol#
technique only works within a single syntax-quoted expression, so your code cannot be mechanically converted into one that does not use gensym
, and might require gensym
@schmee it does and that is the current implementation, but some users predate this variable, so i have to conditionally add it