beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2020-09-26T00:00:13.123800Z

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

fabrao 2020-09-26T00:02:24.125600Z

maybe using something like https://github.com/TheClimateCorporation/claypoole too

2020-09-26T00:02:25.125700Z

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

fabrao 2020-09-26T00:02:48.126300Z

that use thread pool than you use shutdown for it

2020-09-26T00:03:16.126800Z

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

fabrao 2020-09-26T00:04:34.127600Z

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

fabrao 2020-09-26T00:05:17.128100Z

kill all threads suddenly

2020-09-26T00:44:14.128700Z

Don't write programs that need that

zackteo 2020-09-26T01:23:26.129800Z

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

2020-09-26T01:40:20.131200Z

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

2020-09-26T01:52:22.133800Z

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

raymcdermott 2020-09-26T08:24:42.138900Z

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 Newton 2020-09-26T08:33:37.139400Z

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

Jim Newton 2020-09-26T08:33:51.140Z

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.

dharrigan 2020-09-26T08:40:05.140400Z

You can disable them completely in Preferences

dharrigan 2020-09-26T08:40:14.140600Z

(if you are using the desktop client)

dharrigan 2020-09-26T08:43:12.141200Z

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 Newton 2020-09-26T09:32:27.141900Z

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

Jim Newton 2020-09-26T09:34:49.143300Z

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 Newton 2020-09-26T09:35:29.144200Z

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

Jim Newton 2020-09-26T09:41:49.146200Z

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 Newton 2020-09-26T09:43:05.147200Z

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 Newton 2020-09-26T09:49:30.148400Z

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 Newton 2020-09-26T09:52:27.150200Z

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 Newton 2020-09-26T09:52:45.150500Z

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

Cameron 2020-09-26T10:28:25.155300Z

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

kennytilton 2020-09-27T16:48:27.199600Z

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 Newton 2020-09-26T10:34:21.156700Z

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

Jim Newton 2020-09-26T11:07:22.157600Z

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.

schmee 2020-09-26T11:07:44.157900Z

merge might be a better choice here

Jim Newton 2020-09-26T11:19:28.158500Z

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 Newton 2020-09-26T11:19:32.158700Z

merge might be interesting.

sova-soars-the-sora 2020-09-26T13:18:27.161300Z

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

sova-soars-the-sora 2020-09-26T13:21:43.161700Z

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

sova-soars-the-sora 2020-09-26T13:21:55.161900Z

(empty?) apparently not cool

sova-soars-the-sora 2020-09-26T13:22:25.162300Z

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

sova-soars-the-sora 2020-09-26T13:25:43.163500Z

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?

schmee 2020-09-26T13:28:35.164200Z

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

🎯 1
🎵 1
1
sova-soars-the-sora 2020-09-26T13:28:56.164400Z

thank you

sova-soars-the-sora 2020-09-26T13:29:16.164700Z

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

schmee 2020-09-26T13:30:38.165400Z

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?

sova-soars-the-sora 2020-09-26T13:31:50.165700Z

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

sova-soars-the-sora 2020-09-26T13:32:34.165900Z

maybe if (nil? ?^

sova-soars-the-sora 2020-09-26T13:34:33.166100Z

maybe if (not (number? ...

schmee 2020-09-26T13:36:25.166600Z

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

sova-soars-the-sora 2020-09-26T13:37:32.166800Z

correct

sova-soars-the-sora 2020-09-26T13:38:01.167200Z

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

sova-soars-the-sora 2020-09-26T13:38:13.167500Z

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

schmee 2020-09-26T13:39:10.168400Z

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

2020-09-26T14:50:50.168800Z

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

2020-09-26T14:52:46.169Z

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.

2020-09-26T14:55:15.169200Z

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

sova-soars-the-sora 2020-09-26T19:37:59.171300Z

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

👍 1