Fork me on GitHub
#clojure
<
2017-10-30
>
qqq02:10:00

(re-find #"[0-9]+(\.[0-9]*)?" "29482asdf") this returns a vector [complete-match ... groups ... ] is there a way to have it just return the full-match, and not all the intermediate groups ? (I know that I can call first, but I'm trying to get an interface to re-find where it just returns compete string, instead of all groups)

phronmophobic02:10:46

you can use non capturing groups, (re-find #"[0-9]+(?:\.[0-9]*)?" "29482asdf")

phronmophobic02:10:59

by adding the ?: at the start of the group

qqq04:10:23

@smith.adriane: that is much nicer than my current solution of:

(defn re-find0 [pat s]
  (let [ans (re-find pat s)]
    (if (vector? ans)
      (first ans)
      ans)))

danielgrosse07:10:37

@cgrand @ericnormand Around the time, you are visiting the meetup in prague on December, 6th, are you able to visit or speak on another meetup nearby?

yonatanel09:10:04

How do you pass data from clojure.test fixtures to tests (e.g a db connection where you don't know the port at write time)?

qqq10:10:50

how do I create a regex that only ma5ches +-*/ [+-*/] ==> invalid character range

mpenet10:10:57

you need to escape the -

qqq10:10:29

oh, it's looking for a range of '+' to "*/" ?

qqq10:10:38

I can see that being an invalid range

qqq11:10:10

#"[+\-*/]" worked; thanks

Tolga11:10:53

Guys Hi, Is there a problem with clojars? I can not download any dependencies, getting a protol version error?

pesterhazy12:10:25

@qqq, I think alternatively you can move the dash to the end of the character group

tcrawley12:10:36

@tolgayirtici90 clojars is working for me. Can you gist the output you see?

tcrawley13:10:38

What is the output of lein version?

Tolga13:10:20

Leiningen 2.8.1 on Java 1.7.0_51 Java HotSpot(TM) 64-Bit Server VM

tcrawley13:10:07

Did you just recently update lein? 2.8.0 changed the clojars url to point to the CDN instead of the server, and it's possible that old version of java doesn't have the proper TLS features to work with the CDN

Empperi13:10:06

you definitely should update java

Empperi13:10:19

1.7 reached it’s end of life ages ago

Tolga13:10:49

yes i updated lein it 4-5 hours ago

Empperi13:10:18

java 7 supports SNI which would be the most obvious reason for it to not work

Empperi13:10:56

but then again, it might be the CDN is using very strict crypto algorithms for it’s TLS support which might not be supported by java 7

rcustodio13:10:20

I’m still with java 8, I haven’t updated to 9 because of clojure and lein

Empperi13:10:43

leiningen now works with java 9 with the latest update but one cannot say the same about all libraries

rcustodio13:10:43

It gives error on 9, at least it gave it to me, I don’t remember the error

Empperi13:10:00

and clojure 1.9-beta3 at least works with java 9

Tolga13:10:23

i am now updating java then

rcustodio13:10:23

I saw some ppl saying to use clojure 1.9 with java 9, well, stable things should be with stable clojure for now (1.8)

tcrawley13:10:26

We tested the CDN with the latest java 6 when we were setting it up, and it worked, but it's possible that was due to a patch release, and maybe there is a patch to java 7 that provides the same support

Empperi13:10:37

@tolgayirtici90 stick with java 8 for now

Empperi13:10:59

not everything is up to speed with java 9 which brought the module mechanism which is partly backwards incompatible

ghadi13:10:01

(Clojure has always worked on Java 9, it was Lein and Boot that were late to the party. Both are fixed now)

rcustodio13:10:21

@ghadi but clojure 1.8?

tcrawley13:10:30

if you can't update java, you can add the following to your :user profile in ~/.lein/profiles.clj:

:repositories [["clojars" {:url ""}]]
:plugin-repositories [["clojars" {:url ""}]]

ghadi13:10:41

Yup, that worked too @rcustodio

rcustodio13:10:01

Hmm, I will try again with lein latest version

tcrawley13:10:26

That will point you back at the server-based repo instead of the CDN

tcrawley13:10:37

which is what you were using before lein 2.8.0

Tolga14:10:21

btw updating java solved the problem. Thanks all

ghadi16:10:28

#lazyweb Has anyone here done performance comparisons of crypto from Java security providers (built-in or Bouncy Castle) vs. binding to a C library?

phreed16:10:55

I am working on a wrapper for a Java library (https://github.com/ajoberstar/ike.cljj) The library has a lot of varargs in it which can frequently be wrapped with clojure variadics. This requires a bit of arity overloading. The problem is that the original java has typed arguments in addition to differences in arity. What is the recommended way of dealing with this? Here is an example https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createTempDirectory(java.nio.file.Path,%20java.lang.String,%20java.nio.file.attribute.FileAttribute...) I have three ideas: 1) in the implementation for the particular arity, check the type of the object dynamically. 2) treat it like a multimethod, let the dispatch function decide. 3) create separate function names for the wrapping function.

ghadi16:10:08

@phreed a lot of the wrappers libs turn FileAttribute... into a set of keywords. I would not force varargs on the caller.

ghadi16:10:39

I wouldn't mind if a library only helped me create a set of FileAttributes. I have no issues with calling interop code directly. A lot of times it's clearer. (Files/createTempDirectory p s (make-a-set-of-attrs))

phreed16:10:09

@ghadi I see your point. The ugly bit is the java-vararg, if that were simpler then the wrapper is not doing much.

ghadi16:10:07

Varargs in java are just syntactic, it's still fixed arity under the hood. The overloads for createTempDirectory are 2-arity and 3-arity, the clojure ones could be the same thing.

phreed17:10:51

@ghadi I think the point here is that a java-varargs list of options such as FileAttribute is better treated in clojure as a collection, probably a hashmap. In that case the 2-arity can check if the second arg is a map and make the right call. Another way would be to provide a function for constructing the options array from a hashmap and using the java interop directly.

ghadi17:10:17

sounds good.

ghadi17:10:57

hashmap or simple keyword set #{:read :write}, since the attrs are only boolean flags

John Doe17:10:33

Hi, Clojure intermediate here. What is the best way to read big endian binary file?

noisesmith17:10:42

@herman.nutela do you need to make something that parses the binary contents, does it suffice to just get the bytes in an array?

John Doe17:10:30

Sorry, what exactly do you mean?

noisesmith17:10:40

for bytes, java.io.FileInputStream will set you up, for more complex parsing, gloss is a good clojure option https://github.com/ztellman/gloss

noisesmith17:10:56

I mean - if you need bytes, that’s much simpler. If you need to parse a specific format, there’s libraries that help

John Doe17:10:43

Oh, I just need bytes. This library would just be overkill.

noisesmith17:10:41

@herman.nutela simple example

Clojure 1.9.0-beta3
(ins)user=> (java.io.FileInputStream. "/etc/passwd")
#object[java.io.FileInputStream 0x41709512 "java.io.FileInputStream@41709512"]
(ins)user=> (def input *1)
#'user/input
(ins)user=> (.available input)
5253
(ins)user=> (def contents (byte-array *1))
#'user/contents
(ins)user=> (.read input contents)
5253
(ins)user=> (into [] contents)
[35 35 10 35 32 85 115 101 114 32 68 97 116 97 98 97 115 101 10 35 32 10 35 32 7
8 111 116 101 32 116 104 97 116 32 116 104 105 115 32 102 105 108 101 32 105 115
 32 99 111 110 115 117 108 116 101 100 32 100 105 114 101 99 116 108 121 32 111
110 108 121 32 119 104 101 110 32 116 104 101 32 115 121 115 116 101 109 32 105
115 32 114 117 110 110 ... ]

noisesmith17:10:38

@herman.nutela one gotcha with java in general is bytes are always signed, but there’s simple bitwise math tricks that allow all the operations you would expect despite the signedness

John Doe17:10:03

Thank you very much. I just found with-open and input-stream functions. Does they do the same job?

noisesmith17:10:44

input-stream doesn’t help much there since FileInputStream just gives you the thing - but with-open does help if you want to have it automatically close when exiting a specific scope

noisesmith17:10:13

FileInputStream is already an InputStream - though I guess you can use input-stream if you want a BufferedInputStream instead?

John Doe17:10:48

Yep, I'll work with big files, so BufferedInputStream is probably a better choice. Anyway, I think I've got it. Thanks again.

noisesmith17:10:11

I don’t think that’s what the buffer on BufferedInputStream is about at all

noisesmith17:10:36

it adds mark and reset support for streams that don’t implement those methods, but FileInputStream already gives you those methods

noisesmith17:10:54

it’s not a file buffer for performance, it’s a software buffer for replay

noisesmith17:10:41

if file usage needs to be optimized, there are things in java.nio for mmaping where supported

nha17:10:56

Would someone know why the following works in Java:

KafkaMetricsReporter$.MODULE$.startReporters(new VerifiableProperties(props))
But cannot seem to reach $.MODULE$.startReporters from Clojure? (from https://stackoverflow.com/a/47012396/1327651 )

noisesmith17:10:36

$ is part of the name, it’s not it’s own thing

noisesmith17:10:42

it would be (-> KafkaMetricsReporter$ (.MODULE$) (.startReporters (VerifiableProperties. props)))

tanzoniteblack18:10:35

Anyone know if there's an already built solution to logging slow tests with leiningen? (i.e. when running lein test, if a deftest block takes longer than some specified (or assumed) amount of time, it prints a warning)?

nha18:10:41

@noisesmith that looks like an explanation! However I get

Caused by java.lang.RuntimeException
   Unable to resolve symbol: KafkaMetricsReporter$ in this context
I checked as well I can compile the Java code in the answer just fine I tried (-> KafkaMetricsReporter (.MODULE$) (.startReporters (VerifiableProperties. {}))) but then I get
Unhandled java.lang.IllegalArgumentException
   No matching field found: MODULE$ for class java.lang.Class

nha18:10:00

Sorry, disregard the first point, I was missing an import for KafkaMetricsReporter$

nha18:10:01

This worked! (.startReporters (KafkaMetricsReporter$/MODULE$) (VerifiableProperties. props))

nha18:10:06

Thanks a lot!

noisesmith19:10:06

You have unnecessary parens around the access of the static MODULE$ value - they are accepted but not needed (see (Math/PI) for a more obvious version of what that is doing)

noisesmith19:10:00

user=> (Math/PI)
3.141592653589793
user=> Math/PI
3.141592653589793

noisesmith19:10:40

it also accepts (. MATH PI) - which is pretty much only useful for writing macros

eggsyntax19:10:06

Hey folks, I've been working on a single-purpose lib for exploring complex data structures from the REPL as rapidly as possible, with minimum keystrokes. If that's something you spend time doing, I'd love for you to try it out & let me know how it goes. I'll eventually post it in #announcements, but I'm hoping to get feedback from a few more people first. Thanks! https://github.com/eggsyntax/datawalk

kaosko20:10:50

I know about core/bean but does any other lib/function exist that would also allow customizing what to read and include public members as well, not just bean methods?

kaosko20:10:06

oh that's specifically for reading specific protected members

kaosko20:10:22

seems like obj->map from https://dzone.com/articles/clojure-converting-java-object is close to what I need

hiredman20:10:01

it reflectively reads members private or otherwise

hiredman20:10:20

what you want is to reflectively read members

Oliver George21:10:40

There's a gotcha hiding in using a keyword dispatch on multimethods with two args... can you see it?

Oliver George21:10:43

user=> (defmulti m :type)
#'user/m
user=> (defmethod m :t1 [a b] a)
#object[clojure.lang.MultiFn 0x3eb5ed75 "clojure.lang.MultiFn@3eb5ed75"]
user=> (m {} :t1)
{}

Oliver George00:10:56

@U064X3EF3 I can't see this would ever be desirable behaviour but could be surprising. Do you think a patch would be considered? Something which did (k arg1) instead of (apply k args) for the keyword case.

Alex Miller (Clojure team)01:10:41

There are other variadic cases where I don’t think this would work

Oliver George02:10:16

It'd seem a shame to make a special case check for keyword? of the dispatch method

Alex Miller (Clojure team)02:10:27

I don’t understand why you have [a b] in that method - that just seems wrong

Oliver George02:10:09

Yes, the code works but is surprising.

Oliver George02:10:20

Say we have a multi-method which takes two args and we want to dispatch on a keyword from the first arg.

Oliver George02:10:55

The code does that. The dispatch keyword is called as a function (get) which can take one or two args.

Oliver George02:10:07

When get doesn't find the keyword the second arg is returned.

Oliver George02:10:40

That's the oddness. We expect the dispatch-fn to return nil but it returns :t1.

Oliver George02:10:17

To avoid this we need something like

(defmulti m (fn [a b] (:type a)))

Alex Miller (Clojure team)03:10:39

That’s what you should have. The prior example is wrong

Oliver George04:10:55

Fair enough. Thanks.

qqq23:10:12

I'm doing lexing via regex. Is there a re-find which takes an index as an argument? I want to say (search for this regex, but pretend the start of the string is at index i). This is to avoid constant calls to substring.

qqq23:10:28

is there a clojure builtin for (when x (f x)) ? it seems like the type of thing someone has assigned a word to

noisesmith23:10:43

(some-> x (f))

phronmophobic23:10:26

for your lexer, do you plan on support laziness? ie. being able to parse a stream without consuming the whole stream?

phronmophobic23:10:57

there’s several options for readers in java as well as things like java.util.Scanner

phronmophobic23:10:11

that may makes things easier

noisesmith23:10:55

@qqq regarding regex with settable input position, I bet Scanner would help https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

phronmophobic23:10:05

your link is much better. not sure why the first result that came up for me was for java 1.5