clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
kenny 2021-06-02T00:13:17.262Z

Pretty sure that’s a result of defspec, not circleci.

dpsutton 2021-06-02T00:59:52.262500Z

FAIL in (defspec-failure) (file.clj:10)
expected: {:result true}
  actual: {:shrunk {:total-nodes-visited 1, :depth 0, :pass? false, :result false, :result-data nil, :time-shrinking-ms 0, :smallest [-1]}, :failed-after-ms 2, :num-tests 2, :seed 1622595497912, :fail [-1], :result false, :result-data nil, :failing-size 1, :pass? false, :test-var "defspec-failure"}

FAIL in (deftest-failure) (file.clj:8)
expected: (= 1 2)
  actual: (not (= 1 2))
there's a lot more context that would be helpful.

javahippie 2021-06-02T07:18:17.265Z

I believe your only chance would be to transfer that context into the test results xml file somehow? How is the test failure represented in that?

ChillPillzKillzBillz 2021-06-02T06:50:39.263800Z

Maybe this is a repeat question... I am a newbie and I have just stumbled upon spec in Clojure. I was wondering if spec can somehow be used to replicate regular expressions? e.g. say we have a sentence pattern like "Sam is a good boy"... We want the sentence to be parsed by an expression parser to extract words like this: "<name> is a <adjective> boy". We can do this in regular expression. I was just wondering if somebody has tried this using spec?

tatut 2021-06-02T07:03:40.264600Z

you should look into #instaparse for parsing text into syntax trees

ChillPillzKillzBillz 2021-06-02T07:05:54.264800Z

I just joined this channel... do you need me to repost my question here? I am sorry I didn't follow...

2021-06-02T07:19:06.265200Z

It is not designed for that but for something simple patterns it is generally possible https://blog.michielborkent.nl/2017/10/10/parsing-a-circuit-with-clojure-spec/

ChillPillzKillzBillz 2021-06-02T11:16:28.272700Z

This is really interesting... many thanks, I'll look it up!!

reefersleep 2021-06-02T11:22:38.272900Z

@abhi you may also want to look into regal: https://github.com/lambdaisland/regal

ChillPillzKillzBillz 2021-06-03T14:30:24.334Z

wow this is really cool reefersleep!! Many thanks!

ChillPillzKillzBillz 2021-06-03T16:30:30.342800Z

@reefersleep: thanks again for the link to lambdaisland/regal!! I started looking thru the example code. This tries to show how to match a pattern which equates 2 word symbols with "=" sign. I am pasting it here again... (def r [:cat         `[:+ [:class [\a \z]]]`         `"="`         `[:+ [:not \=]]])` . When we execute (regal/regex r) we get #"[a-z]+=[^=]+" as the pattern. How do we make a regal schema to create #"([a-z]+)=([^=]+)" instead? Any ideas? Eventually I'd like to run a command like (re-seq #"([a-z]+)=([^=]+)" "foo=bar") and get (["foo=bar" "foo" "bar"]) for output...

ChillPillzKillzBillz 2021-06-03T16:34:48.343100Z

I solved it myself... I need to use the :capture keyword!! @reefersleep: this is really awesome tool!! Many thanks indeed!!

reefersleep 2021-06-03T16:54:34.351600Z

@abhishek.mazy great that it fits your use case! By the way, if you are not strictly wanting to do regex parsing, I know that @simongray is working on a wrapper for a Java lib that can identify things like adjectives and nouns in sentences, if I remember correctly.

ChillPillzKillzBillz 2021-06-03T16:55:40.351800Z

oh yeah that'll be great as well... I am interested in both regular parsing which is a bit more readable/manageable and language parsing... This is great help!! Many Thanks!

simongray 2021-06-03T16:56:18.352200Z

https://github.com/simongray/datalinguist

1
🙌 1
borkdude 2021-06-02T07:00:03.264500Z

Spec is not intended to be used for text processing

2021-06-02T10:35:04.272500Z

I am using https://github.com/flatland/clojure-protobuf library for serialization and it strips all the default values/fields not provided while sending it over the wire(which is understandable) but also when deserializing at client side, it doesn’t add those default values or missing fields(with default values) back. I checked https://github.com/golang/protobuf golang library which returns those default values. Does anyone have idea why this library doesn’t return default values?

Nom Nom Mousse 2021-06-02T14:14:37.274100Z

Is there a way to create a sorted-map that is sorted by the values?

Nom Nom Mousse 2021-06-02T14:17:13.274500Z

I'll find a different way to do what I want.

Nom Nom Mousse 2021-06-02T14:17:44.274800Z

Oh: https://github.com/clojure/data.priority-map!

Nom Nom Mousse 2021-06-02T14:17:48.275100Z

Hooray

Nom Nom Mousse 2021-06-02T15:36:23.277600Z

I am running an sh job for side effects and I want to be notified when it finishes. However, if it the execution throws an error it never does finish:

user&gt; (future (sh "non-existant-command-fails")) ;; never finishes
How do I get around this problem?

Nom Nom Mousse 2021-06-02T15:38:01.278Z

This does not work either:

(future (try (sh "non-existant-command-fails") (catch Exception ex {:error ex})))

dpsutton 2021-06-02T15:42:18.278600Z

what does work mean? @(future (try (/ 1 0) (catch Exception _e {:it :threw}))) returns {:it :threw}.

Nom Nom Mousse 2021-06-02T15:47:52.280Z

Not working: it never finishes. But the above (with @) is blocking. I'd like to dispatch a job and then be notified when it finishes.

quoll 2021-06-02T15:49:19.281Z

When I do:

(def f (future (try (sh "non-existant-command-fails") (catch Exception ex {:error ex}))))
It returns fine for me. Looking at f I get:
#object[clojure.core$future_call$reify__8477 0x652ce654 {:status :ready, :val {:error #error { ......}}}
If I don’t use def and instead deref immediately, it returns instantly with the IOException

🙏 1
quoll 2021-06-02T15:50:02.281500Z

Are you doing something different?

Nom Nom Mousse 2021-06-02T15:51:50.282200Z

The above works, but if I add a callback function (just println in the below example) the callback is never used:

(def f (future (try (sh "non-existant-command-fails") (println "hoi") (catch Exception ex {:error ex}))))

quoll 2021-06-02T15:52:21.283500Z

That’s because the exception was thrown before the print

Nom Nom Mousse 2021-06-02T15:52:31.284100Z

That is how I was hoping to be notified of the job being finished (or having errored)

quoll 2021-06-02T15:52:39.284600Z

You could use a finally block?

Nom Nom Mousse 2021-06-02T15:52:43.284700Z

I see the reason why, I just wonder how to get around it 🙂

Nom Nom Mousse 2021-06-02T15:52:49.284900Z

Ah, I'll try 🙏

2021-06-02T16:40:45.286Z

Anyone know any good time zone conversion libraries?

seancorfield 2021-06-02T16:41:17.286500Z

Depends what you mean by that — for Clojure, I’d just use Java Time directly for most time/date stuff.

💯 4
James Carr 2021-06-02T17:25:47.287800Z

Anyone using Datadog APM with Clojure? Or even more in particular ... using Clojure + open telemetry with Datadog APM?

➕ 1
James Carr 2021-06-03T14:49:38.334200Z

@kenny what was your experience with stack traces?

James Carr 2021-06-03T14:51:13.334400Z

we have a few apps setup and it is working fine, but 500 error responses just show ERR_CODE_2 rather than the stacktrace. A java based app using the same otel gateway has stacktraces visible, so wondering where the issue lies. Have a ticket open with DD on it

ghadi 2021-06-02T17:33:21.287900Z

no, but interested in this topic :simple_smile:

javahippie 2021-06-02T17:54:14.289Z

There was just another APM question last week, how about creating a channel about the topic?

javahippie 2021-06-02T17:54:42.289200Z

Just saw, there is #observability

James Carr 2021-06-02T18:40:57.290800Z

lol the other one was me 🙂

🙂 1
kenny 2021-06-02T20:34:46.292300Z

We use Datadog APM and report to it via opentacing Java lib. Yeah, I’m getting some déjà vu here.

phronmophobic 2021-06-02T20:50:06.293100Z

Is this expected behavior?

&gt; (Math/abs 30359687764)
30359687764

&gt; (#(Math/abs %) 30359687764)
294916692
&gt; (#(Math/abs ^long %) 30359687764)
30359687764

&gt; ((fn [x] (Math/abs x)) 30359687764)
294916692
&gt;&gt; ((fn [x] (Math/abs ^long x)) 30359687764)
30359687764

alexmiller 2021-06-02T20:58:07.294200Z

I think this may already be logged (has to do with the coercion/casting path for primitive long vs object Long) but please ask these kinds of things on https://ask.clojure.org

ghadi 2021-06-02T20:58:18.294600Z

there are a small cluster of bugs in this area

alexmiller 2021-06-02T20:59:10.294900Z

there are several questions there that seem like the same thing already

phronmophobic 2021-06-02T21:00:02.295700Z

:thumbsup:

alexmiller 2021-06-02T21:01:07.296200Z

if you start asking a question on ask.clojure btw, it will suggest similar existing questions

👍 1
phronmophobic 2021-06-02T21:05:28.296800Z

Just noticed that it seems like those questions and tickets refer to Java 1.8. My above results are on Java 11

alexmiller 2021-06-02T21:09:14.297Z

doesn't matter

alexmiller 2021-06-02T21:09:30.297200Z

nothing in this area has changed since Java 1.0 afaik :)

alexmiller 2021-06-02T21:10:26.297400Z

maybe there have been changes in how Clojure reflection worked against Java that would be relevant, dunno