Fork me on GitHub
#clojure
<
2020-10-03
>
dominicm05:10:43

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?

andy.fingerhut05:10:40

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

dominicm06:10:08

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

dominicm06:10:55

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

vlaaad07:10:41

Overloaded methods in Java require having different arguments

vlaaad07:10:13

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

vlaaad07:10:51

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

dominicm07:10:03

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

murtaza5213:10:34

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 ?

dominicm13:10:47

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

dominicm13:10:56

There's a few other ns- functions too

murtaza5213:10:05

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

schmee13:10:35

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

murtaza5213:10:06

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)

schmee13:10:24

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

vncz13:10:33

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

schmee13:10:00

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

vncz13:10:05

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

schmee13:10:05

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

vncz13:10:35

All right, thanks!

murtaza5214:10:57

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

schmee14:10:29

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

👍 3
quoll19:10:48

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

murtaza5214:10:53

great thanks

murtaza5214:10:49

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

andy.fingerhut14:10:14

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.

👍 3
murtaza5214:10:07

@andy.fingerhut cool thanks for the tip

murtaza5215:10:06

@borkdude thanks will check it out

didibus18:10:03

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

didibus23:10:30

You mean the function "for"? I have a use case where I need to allow other non Clojure programmers to define selections over maps. So I wondered if someone implemented some SQL engine over standard vector of maps or such thing?

seancorfield00:10:53

Datalog perhaps?

didibus02:10:53

I thought about it, but I feel asking non Clojure devs to learn datalog isn't that much better then asking them to learn how to map/filter in Clojure itself. Which is what I have now, just take some Clojure code.

seancorfield03:10:55

I admit, having a SQL JDBC driver that works on named collections of hash maps is quite appealing 🙂

seancorfield03:10:21

This might be a good starting point if you want to build a DSL for them to use? http://www.multunus.com/blog/2016/11/building-sql-like-dsl-clojure-part-1/

fullNameHere18:10:29

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

jumar18:10:01

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

fullNameHere18:10:06

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

w08r19:10:31

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

fullNameHere02:10:47

The reason Im using it is simply because it was the first thing that google brought up when dealing with dates. Its a throw away project so I didnt look to deep into it.

👍 3
schmee19:10:01

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

schmee19:10:57

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 Douglass19:10:28

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

w08r19:10:54

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

schmee20:10:45

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

schmee20:10:16

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

👍 3
w08r20:10:42

Thanks again!

seancorfield21:10:42

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

👍 3
w08r07:10:18

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

didibus23:10:30
replied to a thread:For

You mean the function "for"? I have a use case where I need to allow other non Clojure programmers to define selections over maps. So I wondered if someone implemented some SQL engine over standard vector of maps or such thing?

Eamonn Sullivan23:10:44

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?