clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
dominicm 2020-10-03T05:52:43.438900Z

If I have a java class which has 2 methods get, one which returns a String, one which returns a byte array. How do I inform Clojure I'd like the byte array form?

2020-10-03T05:54:40.439900Z

What are the signatures of the two get methods besides the return values? That is, their number and types of parameters?

dominicm 2020-10-03T06:19:08.440Z

@andy.fingerhut Are differing args a prerequisite for this in java?

dominicm 2020-10-03T06:20:55.440100Z

In this case, it is String vs byte array arguments too. I am curious to know if it was just get() if java return typing works

vlaaad 2020-10-03T07:07:41.440200Z

Overloaded methods in Java require having different arguments

vlaaad 2020-10-03T07:08:13.440300Z

Otherwise compiler can't guess what was meant to be called

vlaaad 2020-10-03T07:08:51.440400Z

In cases where the return is ignored, for example, or assigned to Object variable

dominicm 2020-10-03T07:18:03.440900Z

Okay, cool. So I'll never run into that situation then! Great.

murtaza52 2020-10-03T13:39:34.442200Z

I have a ns in which I am declaring a bunch of vars (def a 1) (def b 2) is there a way I can get a list of all vars defined in a ns ?

dominicm 2020-10-03T13:40:47.443Z

@murtaza52 ns-publics or ns-interns, depends what you're after

dominicm 2020-10-03T13:40:56.443300Z

There's a few other ns- functions too

murtaza52 2020-10-03T13:49:05.444200Z

@dominicm thanks, both of them are giving me the intended result, how do they differ ?

schmee 2020-10-03T13:53:35.445200Z

@murtaza52 ns-interns gives you all mappings, including private functions

murtaza52 2020-10-03T13:55:06.446300Z

thanks @schmee also is there a way to specify the current ns, trying to see if I can escape hardcoding the ns name when calling (ns-publics 'ns-name)

schmee 2020-10-03T13:55:24.446600Z

you can use *ns* as a shorthand for the current namespace

vncz 2020-10-03T13:57:33.447Z

Is there a specific function I can use to map on a map and change its values?

schmee 2020-10-03T13:58:00.447800Z

no, you’ll have to use something like reduce-kv or Specter

vncz 2020-10-03T13:58:05.448Z

I see almost everybody suggesting to write your own function such as

vncz 2020-10-03T13:58:20.448100Z

schmee 2020-10-03T13:59:05.448700Z

yeah, if you don’t want to use a lib for it then that is the way

vncz 2020-10-03T13:59:35.448900Z

All right, thanks!

murtaza52 2020-10-03T14:01:33.449200Z

@schmee thanks

murtaza52 2020-10-03T14:01:57.449800Z

is there a way to have private (def- ) just like private (defn- )

schmee 2020-10-03T14:03:29.450300Z

yes: (def ^{:private true} your-var), no shorthand for that one

1👍
quoll 2020-10-05T19:42:48.013300Z

Since there’s only one element in the meta, there’s the tiny abbreviation of saying: (def ^:private your-var) But it’s not much

murtaza52 2020-10-03T14:04:53.450800Z

great thanks

murtaza52 2020-10-03T14:17:49.451800Z

so if I have *ns* in a fn, then it refers to the ns from which the fn is called.

2020-10-03T14:25:14.452800Z

One way to get the ns where the function is defined is to have something like (def my-ns *ns*) in the namespace where a function is defined, and use my-ns in the definition of that function.

1👍
murtaza52 2020-10-03T14:29:07.453200Z

@andy.fingerhut cool thanks for the tip

murtaza52 2020-10-03T15:31:06.454200Z

@borkdude thanks will check it out

2020-10-03T18:17:03.456Z

Is there a library that lets me run SQL over a vector of maps?

2020-10-03T18:32:05.456200Z

For

2020-10-03T18:54:29.457300Z

Hey guys, I'm using the java-time api. If I do something like (def now (local-date)) (println now) it prints #object[java.time.LocalDate 0x153739a 2020-10-03] how could I make it so it only prints the date? I've tried many things along the lines of (println (. java.time.LocalDate now)) with no success

jumar 2020-10-03T18:57:01.457700Z

(str (java.time.LocalDate/now))
"2020-10-03"

2020-10-03T18:58:06.458500Z

Damn, that easy. Thank you so much. Was stuck for way longer than Id like to admit.

2020-10-03T19:45:31.460100Z

Out of interest is there a reason to use java time direct over and above clojure.java-time?

schmee 2020-10-03T19:46:01.460700Z

I’d flip it around: is there a reason to use clojure.java-time over java.time? 🙂

2020-10-03T19:47:13.461Z

Touche!

schmee 2020-10-03T19:48:57.461700Z

java.time is actually a legit good API, and it’s also compatible with Clojure by default since it’s immutable classes all the way

Darin Douglass 2020-10-03T19:55:28.467700Z

^ I second this. We just interop with java.time directly. My only gripe is the the inst reader macro is actually a java.util.Date and not an Instant (which I get for back-compat/historical reasons)

2020-10-03T19:56:54.469100Z

Thanks for these perspectives. The rationale on the clojure-time page seems reasonable, is it in general only used in edge cases then (I appreciate this is a question that probably belongs in #beginners, but I loiter here too and obviously this came up ...)

schmee 2020-10-03T20:03:45.470600Z

it’s a matter of taste I think, some people prefer to avoid interop, I prefer to not use libraries that “just” wrap a Java library unless it provides substantial benefits over using library directly, such as providing some data- or macrodriven abstraction over a heavy OOP / imperative API

schmee 2020-10-03T20:04:16.471400Z

in the case of java.time, IMO a wrapper lib is not warranted since the library is so easy to use via interop already

1👍
2020-10-03T20:04:42.472Z

Thanks again!

schmee 2020-10-03T20:04:57.472200Z

np! 🙂

seancorfield 2020-10-03T21:57:42.474300Z

@will08rien At work we use a mixture of Java Time via interop and also clojure.java-time -- the latter makes certain coercions and date arithmetic a lot "cleaner" (and easier to read) than plain interop.

1👍
2020-10-04T07:46:18.489800Z

Thanks Sean. I'll keep this in mind and try to make the decision on a case by case basis.

Eamonn Sullivan 2020-10-03T23:52:44.478400Z

Hi all, I have a really basic build/deploy question. In https://github.com/eamonnsullivan/github-pr-lib, I have a simple little lib that uses the Github GraphQL API to create/modify/merge pull requests. It all worked fine until I had the bright idea to move the GraphQL queries and mutations into separate files and slurp them in to the source code like

(def get-repo-id-query (slurp "./src/eamonnsullivan/graphql/get-repo-id-query.graphql"))
Now, everything works fine locally, but not when I build and deploy the library.
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
./src/eamonnsullivan/graphql/get-repo-id-query.graphql (No such file or directory)
What is the correct way to include resources like this in a build and how do I refer to them in the source code?