clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2020-10-01T00:04:29.360800Z

I see. I’m fairly new to clojure. So I don’t know too much on the java ‘libraries’… Do I need to require a certain namespace to use ManagementFactory?

emccue 2020-10-01T00:21:28.361Z

you need to import the class

emccue 2020-10-01T00:23:20.361200Z

are you running in a repl or do you have a file with a ns at the top?

2020-10-01T00:24:14.361400Z

ns at the top

emccue 2020-10-01T00:24:21.361600Z

okay add

emccue 2020-10-01T00:24:47.361800Z

(ns whatever
  (:require [] ...)
  (:import (java.lang.management ManagementFactory)))

2020-10-01T00:29:01.362Z

damn didn’t know you can do that! I guess thats one of the beauties of Clojure. So whatever is in the Oracle docs thats java, I can import and use that?

2020-10-01T00:38:06.362200Z

I really appreciate your help tonight! I can move forward and run with this!

emccue 2020-10-01T00:40:03.362400Z

yeah, all of clojure maps to the "java metaphysics" in some way

emccue 2020-10-01T00:40:14.362600Z

and you can import and use any classes you want

emccue 2020-10-01T00:40:52.362800Z

though certain things will be easier than others - "spring-like" stuff with annotations or stuff that reflectively calls constructors can be a pain

2020-10-01T00:41:50.363Z

I’ve just been using the core library, and its all that I’ve needed so far. But now its a whole new world! lol

g7s 2020-10-01T07:33:24.366800Z

This might have been asked before but what is the clojure way to catch an ex-info and rethrow it with augmented ex-data (while not changing other parts of the exception) ?

alexmiller 2020-10-01T13:08:56.373Z

ExceptionInfo objects are immutable, so it's not possible to actually augment the original exception object. You can pull out the message, data, and if desired, stack trace, and make a new ex-info though and throw that. The message and data are pretty obvious but you can use .getStackTrace and .setStackTrace to transfer that.

alexmiller 2020-10-01T13:14:06.373400Z

you might also be interested in https://github.com/scgilardi/slingshot which has a bunch of interesting facilities in this area

oly 2020-10-01T14:30:17.375Z

any decent libraries for GCP in particular I want to use cloud storage I see we have amazonica and aws-api's for amazon cloud but not seeing anything that seems as upto date or as comprehensive, anyone have any experience in this area ?

oly 2020-10-02T08:03:23.386300Z

Thanks for the info, we have moved from AWS to GCP a while back but not tying your apps to any infrastructure makes moving between them much simpler, quite likely we will re asses which is better for us at some point.

lukasz 2020-10-01T15:07:45.375300Z

In general GCP's Java SDK is pretty ok to use directly from Clojure (in my experience), so a wrapper is not necessary

➕ 1
peterschwarz 2020-10-01T15:29:25.375600Z

You could ask over in #google-cloud. It’s not terribly active, but people seem to respond to questions

🤘 1
oly 2020-10-01T15:29:55.375800Z

okay good to know, I was hoping to find a storages client that did aws cloud storage spaces and minio all in one so the service is not tied to a platform

lukasz 2020-10-01T17:21:34.376300Z

If it helps - Minio can act as a proxy for google cloud storage, so you can use a S3 client, talk to minio and that will translate API calls from S3-style to Google Cloud

lukasz 2020-10-01T17:22:40.376500Z

I'm pretty sure a universal client for Mino, S3 and Google Cloud doesn't exist in Clojure - but it's not hard to implement using protocols etc. We had one, but eventually we settled 100% on S3 and use Minio only in CI

Karo 2020-10-01T17:46:00.376800Z

Hi all, how Unauthorizedaccessexception can be thrown in clojure? thanks

Karo 2020-10-02T07:28:56.385700Z

(defn execute-study-header-get [study_uuid study_id database_id param]
  (let [sponsor_id (str (get-sponsor-config param))
        study-selections (get-study-selections-with-forecasts sponsor_id)
        data (map (fn [x] (dissoc x :sponsorName :projectName :studyStatus :phase :indication
                                   :forecastID :forecastName)) (:data study-selections))
        result (map (fn [input] (and (= (:studyID input) study_id)
                                     (= (:databaseID input) database_id)
                                     (= (:UUID input) study_uuid))
                      ) data)
        check (some #(= % true) result)]
    (if (not= check true) "401" (execute-study-header study_uuid study_id database_id))))

My task is to throw UnauthorizedAccessException 401 instead of string "401" in the last line of the code.

Karo 2020-10-02T07:31:29.385900Z

I am using clojure on the jvm.

jimmy 2020-10-02T13:44:38.395700Z

Is this is some assignment? If so you should ask the person who gave it to you for clarification. There is no built-in exception called UnauthorizedAccessException. So you can use ex-info or you can make a custom exception. https://stackoverflow.com/questions/3835331/custom-exceptions-in-clojure

Karo 2020-10-02T14:16:03.406800Z

ok, thank you

Toyam Cox 2020-10-01T17:49:27.376900Z

https://clojuredocs.org/clojure.core/throw

1
Toyam Cox 2020-10-01T17:49:57.377200Z

but the exception you name seems to be a .Net thing

Karo 2020-10-01T18:08:01.377600Z

Yes I can not find that exception, I tried to throw it using java lang esception class, this also doesn not work.

g7s 2020-10-01T18:40:14.380200Z

@alexmiller Thanks! I may look into slingshot to see if it fits my needs

jimmy 2020-10-01T19:00:56.380300Z

If you could put the exact code you tried, that might be helpful for people to know what you are looking for. UnauthorizedAccessException is not a part of the JVM but of the CLR (.Net). Are you using clojure on the jvm? If so, do you have the full name of the exception you want to throw? Do you need to throw a specific exception, or just want an exception to communicate a particular message? If the latter, try out https://clojuredocs.org/clojure.core/ex-info

borkdude 2020-10-01T21:27:47.381100Z

I think even java exceptions are effectively immutable right?

borkdude 2020-10-01T21:28:39.381400Z

hmm, it does have setStackTrace but not setMessage

borkdude 2020-10-01T21:29:16.381600Z

> If the stack trace of this Throwable is not writable, calling this method has no effect other than validating its argument.

2020-10-01T21:54:04.381900Z

Also initCause, which docs say is typically called within the constructor, but if not, it can be called at most once per Throwable object after construction.

borkdude 2020-10-01T21:57:43.382100Z

thanks.

2020-10-01T21:58:08.382300Z

missed immutability by that much 🙂

😅 1
borkdude 2020-10-01T21:59:34.382500Z

I've tried mutating exceptions unsuccessfully before that's why I assumed they were immutable by design, but not quite

2020-10-01T22:00:20.382700Z

Then of course there is the "peeking under the Clojure API covers" kind of cheating where you can mutate Clojure collections, to no good effect.

2020-10-01T22:01:17.382900Z

Unless your goal is to get pedants like me into a discussion of what immutable really means 🙂

borkdude 2020-10-01T22:04:51.383100Z

Reminds me of "private is a state of mind" by Alex Miller. Probably immutability is as well, although Clojure does quite a good job to enforce it (better than private ;))

emccue 2020-10-01T22:05:43.383300Z

I'm not multi cloud or anything - I just have a local/test impl for stuff - but even protocols might be overkill depending on the task

emccue 2020-10-01T22:06:18.383500Z

I settled on just having maps with functions in them

emccue 2020-10-01T22:06:20.383700Z

emccue 2020-10-01T22:06:43.384100Z

emccue 2020-10-01T22:06:56.384500Z

and having the public api just call those functions in the map

2020-10-01T22:07:23.384700Z

I haven't heard that quote before, but yeah, that is also sure to raise discussion among developers who like stronger language-enforcable gaurantees on information hiding.

borkdude 2020-10-01T22:08:59.384900Z

I think more people are happy with being able to hack around private then the other way around in Clojure

lukasz 2020-10-01T22:53:18.385100Z

Sure that works too. We use records+protocols because we use Component and we model api clients as components too - including S3 and such. Just makes it easier to manage dependencies of things