This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-30
Channels
- # aws (5)
- # aws-lambda (2)
- # beginners (29)
- # boot (5)
- # cider (3)
- # cljs-dev (3)
- # cljsjs (2)
- # clojure (112)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-italy (9)
- # clojure-nl (2)
- # clojure-russia (5)
- # clojure-spec (49)
- # clojure-uk (41)
- # clojurescript (157)
- # core-logic (5)
- # crypto (1)
- # cursive (12)
- # data-science (38)
- # datomic (31)
- # emacs (3)
- # events (2)
- # garden (3)
- # graphql (10)
- # immutant (4)
- # jobs (3)
- # juxt (5)
- # klipse (1)
- # luminus (3)
- # off-topic (40)
- # om (1)
- # onyx (39)
- # other-languages (7)
- # protorepl (3)
- # re-frame (40)
- # reagent (60)
- # ring (8)
- # ring-swagger (14)
- # shadow-cljs (159)
- # spacemacs (1)
- # specter (6)
- # uncomplicate (3)
- # yada (2)
(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)
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)?
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?
@tcrawley https://gist.github.com/anonymous/4bd2d48f05502968313e8b0cdc656826 here is the output
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
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
leiningen now works with java 9 with the latest update but one cannot say the same about all libraries
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)
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
#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 (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.
@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.
@herman.nutela do you need to make something that parses the binary contents, does it suffice to just get the bytes in an array?
which one?
for bytes, java.io.FileInputStream will set you up, for more complex parsing, gloss is a good clojure option https://github.com/ztellman/gloss
I mean - if you need bytes, that’s much simpler. If you need to parse a specific format, there’s libraries that help
@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 ... ]
@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
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?
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 https://stackoverflow.com/a/47012396/1327651 )$ 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
This worked! (.startReporters (KafkaMetricsReporter$/MODULE$) (VerifiableProperties. props))
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)
3.141592653589793
user=> Math/PI
3.141592653589793
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! https://github.com/eggsyntax/datawalk
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?
https://github.com/arohner/clj-wallhack might be a good start
seems like obj->map from https://dzone.com/articles/clojure-converting-java-object is close to what I need
There's a gotcha hiding in using a keyword dispatch on multimethods with two args... can you see it?
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)
{}
@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.
There are other variadic cases where I don’t think this would work
Fair enough.
It'd seem a shame to make a special case check for keyword? of the dispatch method
I don’t understand why you have [a b] in that method - that just seems wrong
Yes, the code works but is surprising.
Say we have a multi-method which takes two args and we want to dispatch on a keyword from the first arg.
The code does that. The dispatch keyword is called as a function (get) which can take one or two args.
When get doesn't find the keyword the second arg is returned.
That's the oddness. We expect the dispatch-fn to return nil but it returns :t1
.
To avoid this we need something like
(defmulti m (fn [a b] (:type a)))
That’s what you should have. The prior example is wrong
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
for eg, https://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#next(java.util.regex.Pattern)
@qqq regarding regex with settable input position, I bet Scanner would help https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
oh, haha
your link is much better. not sure why the first result that came up for me was for java 1.5