Fork me on GitHub

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


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


by adding the ?: at the start of the group


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


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


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


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


you need to escape the -


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


I can see that being an invalid range


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


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


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


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


What is the output of lein version?


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


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


you definitely should update java


1.7 reached it’s end of life ages ago


yes i updated lein it 4-5 hours ago


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


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


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


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


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


and clojure 1.9-beta3 at least works with java 9


i am now updating java then


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)


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


@tolgayirtici90 stick with java 8 for now


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


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


@ghadi but clojure 1.8?


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 ""}]]


Yup, that worked too @rcustodio


Hmm, I will try again with lein latest version


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


which is what you were using before lein 2.8.0


btw updating java solved the problem. Thanks all


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


I am working on a wrapper for a Java library ( 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,%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.


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


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


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


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.


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


sounds good.


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?


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


for bytes, will set you up, for more complex parsing, gloss is a good clojure option


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.


@herman.nutela simple example

Clojure 1.9.0-beta3
(ins)user=> ( "/etc/passwd")
#object[ 0x41709512 ""]
(ins)user=> (def input *1)
(ins)user=> (.available input)
(ins)user=> (def contents (byte-array *1))
(ins)user=> (.read input contents)
(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 ... ]


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


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


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.


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


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


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


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


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 )


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


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


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


@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


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


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


Thanks a lot!


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)


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


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


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!


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?


oh that's specifically for reading specific protected members


seems like obj->map from is close to what I need


it reflectively reads members private or otherwise


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=> (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.


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.


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


(some-> x (f))


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


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


that may makes things easier


@qqq regarding regex with settable input position, I bet Scanner would help


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