Fork me on GitHub
#beginners
<
2020-09-26
>
hiredman00:09:13

there is no reliable way to stop a thread (including future-cancel) from another thread, without the thread co-operating (like polling the atom)

hiredman00:09:25

(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")

fabrao00:09:48

that use thread pool than you use shutdown for it

hiredman00:09:16

shutdown a threadpool generally does not stop the threads if they are actively doing something, it waits for them to stop

fabrao00:09:34

but if is this needed in my program? What do you sugest to use?

fabrao00:09:17

kill all threads suddenly

hiredman00:09:14

Don't write programs that need that

zackteo01:09:26

Hi guys, quick qn, as a beginner should I try using kee-frame or use reframe directly? o:

kimim01:09:20

#java-interop Hello, how to invoke default constructor of java class? such as Company(); which is not explicitly defined. thanks.

hiredman01:09:22

If the class declares any constructors then it won't get a default constructor, otherwise the default constructor is invokable just like any other

raymcdermott08:09:42

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.

Jim Newton08:09:37

I have a question about slack. I get a message like this.

Jim Newton08:09:51

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.

dharrigan08:09:05

You can disable them completely in Preferences

dharrigan08:09:14

(if you are using the desktop client)

dharrigan08:09:12

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

Jim Newton09:09:27

is the suggestions to disable all notifications from every tool. or should there be a preference in slack to disable notifications?

Jim Newton09:09:49

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.

Jim Newton09:09:29

I don't want notifications enabled. but there's now no button to undo what I just did. :-(

Jim Newton09:09:49

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.

Jim Newton09:09:05

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.

Jim Newton09:09:30

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.

Jim Newton09:09:27

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]]

Jim Newton09:09:45

rather than java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol

Cameron10:09:25

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

andy.fingerhut14:09:50

Learning to find the relevant part of a full JVM stack trace is a useful skill, although one that appears daunting at first.

kennytilton16:09:27

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. 🤷

Jim Newton10:09:21

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 [email protected] (:* :sigma) nil)))))))

andy.fingerhut14:09:46

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.

andy.fingerhut14:09:15

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

Jim Newton11:09:22

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.

schmee11:09:44

merge might be a better choice here

Jim Newton11:09:28

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

Jim Newton11:09:32

merge might be interesting.

sove13:09:27

...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?

sove13:09:43

How can I check if a nested val in an atom is not yet set ?

sove13:09:55

(empty?) apparently not cool

sove13:09:25

maybe (not (contains? ... )) ?

sove13:09:43

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?

schmee13:09:35

(def a (atom {"" {}}))
  (swap! a update-in ["" :streak-count] (fnil inc 0))

1
🎯 1
🎵 1
sove13:09:56

thank you

sove13:09:16

I just want to zero it out in this case... maybe (constantly 0) ?

schmee13:09:38

if you want to set it regardless then (swap! a assoc-in ["" :streak-count] 0) should work, no?

sove13:09:50

oh well my problem is actually testing if it is set or not

sove13:09:34

maybe if (nil? ?^

sove13:09:33

maybe if (not (number? ...

schmee13:09:25

so if it’s there, do nothing, if it’s not set it to zero?

sove13:09:01

but i think i could avoid this line completely with (fnil inc 0) !

sove13:09:13

however for the time being (not (number? )) seems to do the trick.

schmee13:09:10

does it make sense to have :streak-count set to 0 as default, when you create your user?

sove19:09:59

@schmee it does and that is the current implementation, but some users predate this variable, so i have to conditionally add it

👍 1