Fork me on GitHub
#clojure
<
2020-04-16
>
murtaza5206:04:54

Need help with the following regex (clojure.string/replace "inventory-of-beef-cows:-(-20-to-49-head)" (re-pattern #"\\Q,|:-|(|)\\E") "") I want to replace brackets (and ), however the above doesnt seem to work.

andy.fingerhut07:04:43

What is the result you hope to get, for that sample input string?

Cameron07:04:59

are you just trying to replace ( and ) with ""? (ie something like (clojure.string/replace "inventory-of-beef-cows:-(-20-to-49-head)" #"[()]" "") ? I admit I'm looking at your regex and trying to figure out what's going on, it seems almost arbitrary to me and I'm wondering if its just utilizing some construct I'm unfamiliar with (for instance, I'd surprisingly never heard of \Q and \E until now)

andy.fingerhut07:04:51

If your goal is to eliminate all occurrences of the characters ( and ) from the input string, regardless of in what order they occur, and regardless of whether they are "balanced parentheses" or not, then Cameron's suggestion is correct.

murtaza5207:04:59

@zdot101 @andy.fingerhut I am trying to eliminate any occurences of , :- ( and ) from the string.

Cameron07:04:50

(clojure.string/replace "in,,,:vent))ory-of-be:-ef-cows:-(-20-to-49-he:ad)" #"[(),]|:-" "") should do

Cameron07:04:13

ah, in that case I see what you were at least going for

Cameron07:04:49

#",|:-|\(|\)" for one closer to what you were going for

murtaza5210:04:25

thanks, that works ! just for my understanding, how does the above regex differ from this one #"[(),]|:-" "")

hindol10:04:56

Both RegExes work?

Cameron12:04:33

oh, #",|:-|\(|\)" just separates each individual case by a | as you had it , while #"[(),]|:-" grouped (,`)`,and , into one character set`[..]` to sort of phrase it as "one of [left parenthesis, right parenthesis, comma] or :-"

Cameron07:04:54

In messing around with the \Q and \E version though, I do wonder, as I get strange behavior; I get the impression \Q and \E are for escaping text, but since the entire regex that way is escaped, you'd think it'd be trying to match literally on ,|:-|(|) all together, rather than , or :- or ( or ), and that it'd then fail. But when I test it out, it specifically seems to match on :- (and only :-) )

Cameron07:04:05

and if this means it does somehow not escape everything (such as the |), it doesn't explain why only :- seems to work

Cameron07:04:20

anyways I'm going to sleep, hope it all goes well

Ramon Rios12:04:35

https://clojure.org/guides/faq#illegal_access Hello folks. I'm trying to setup this flag --illegal-access=debug but the docs does not show where/how to apply it. Does anybody did that before?

Ramon Rios12:04:45

Ok, for some reason it's failing on my git pipeline even with my tests running file.

Eugen13:04:35

hello guys, I'm working to improve clojure tooling around gradle - specifically clojurephant and this issue https://github.com/clojurephant/clojurephant/issues/44 . I'm looking for some feedback if you ever tried / considered clojure/script + gradle - what would you need know /work to get you started? I have Java experience and gradle experience and I just started learning clojure so for me it's going to be a learning experience. Please add your feedback on the issue or here. If you know someone who has feedback, please let him know.

Michael J Dorian13:04:28

Are there any especially recommended resources on learning how to speed up clojure code? I'm profiling for my specific problem, but, I feel like a stronger background in the concepts of fast clojure would help me as well. If my profiling basically boils down to the fact that I am running filter on large collections constantly, what would I look for to try and find a better implementation?

Michael J Dorian14:04:07

Is there a work in progress I can look at for the docs section? The profiler I use is the first one on their source code list

vlaaad14:04:42

Ah you already use clj-async-profiler

Michael J Dorian14:04:18

Yeah, it's really nice simple_smile

phronmophobic17:04:10

i’m also in the middle of trying to speed up some code. this is a great resource. thanks for sharing :thumbsup:

alexmiller14:04:21

depending on what you're doing, transducers may be faster than seqs

alexmiller14:04:29

particularly, applying multiple filters or other transformations using seqs over large collections means n intermediate seqs vs transducers which can apply all of them in a single pass over the data

Michael J Dorian14:04:07

Thanks, I'll look into that! There are a lot of consecutive filters happening 👍

vlaaad14:04:09

You can parallelize them using reducers, for example https://clojure.org/reference/reducers

vlaaad14:04:13

or core.async

Michael J Dorian14:04:15

I managed to parallelize my system using agents, since there are always hundreds of agents in the queue, it very efficiently maxes out all of my processor cores while also being much cleaner that the weird pseudo-queue I had built originally 👍

Michael J Dorian14:04:46

Is there any overhead with multi-arty functions?

Michael J Dorian14:04:14

Nice, sorry for the silly question! I have a multi-arity func in a hot loop

didibus16:04:52

Multi arity is pretty much zero overhead, because the arity is known statically at compile time and is determined when compilation happens, so dispatch is static

Michael J Dorian16:04:50

That makes sense, thanks!

Alexis Vincent15:04:21

core.async / var question here: Is there a way to override the MAX-QUEUE-SIZE for a particular chan. I have a case where I create a promise-chan that resolves to some status when some computation finishes. And there are more then 1024 listeners who need to block until the status is finished and I don’t want to limit the amount of possible listeners. The amount of listeners scales with the complexity of our APP and could up to 5000 pending takes, and in another case scales with the amount of active connections in a partition, again is unlikely to go above 2000. I want to be able to set these limits on a per chan level. Not really a solution to set this globally (although still better), since this is an internal lib and I don’t want to pass on these limits to the app level. Its kind of ok for this to be some hack job with redefining MAX-QUEUE-SIZE with a patch. I’m kind of thinking a (binding [clojure.core.async.impl.protocols/MAX-QUEUE-SIZE 2000] …) or something similar is what im after, however clojure.core.async.impl.protocols/MAX-QUEUE-SIZE isnt dynamic so that wouldnt work. Any recomendations?

Alexis Vincent15:04:18

Is there a way for instance to patch a var to make it dynamic?

alexmiller16:04:08

Follow ups in #core-async please...

mike_ananev17:04:08

Hello. Is there any known performance issues with clojure.tools.logging? I want to switch to clojure.tools.logging from io.pedestal.log. AFAIK, pedestal performs logging in async mode and I didn't see any performance problems.

hiredman17:04:27

tools logging is so abstract it is difficult to say things generally about it, pedestal logging if I recall correctly a shim on top of slf4j, but tools.logging is a shim on top of a bunch of different possible libraries, and it just sort of probes the classpath looking for possible backends and picks one

hiredman17:04:02

so you may not even be using the same logging backend anymore

seancorfield19:04:22

As of tools.logging 0.6.0 (from February) you can provide a JVM option to force it to use a specific logger https://github.com/clojure/tools.logging/#selecting-a-logging-implementation

👀 4
KJO21:04:28

While looking at integrating Clojure with a Cadence workflow server I was attempting an almost direct conversion using Cadence's quick start docs. However, I've run into a problem with annotations. If I have an interface: (definterface HelloWorldActivities (^{ActivityMethod {:scheduleToCloseTimeoutSeconds 100}} ^void say [^String name])) and then use gen-class on an object that implements that interface, I get a class file whose relevant section disassembles to { public abstract void say(java.lang.String); descriptor: (Ljava/lang/String;)V flags: (0x0401) ACC_PUBLIC, ACC_ABSTRACT RuntimeVisibleAnnotations: 0: #8(#9=J#10) com.uber.cadence.activity.ActivityMethod( scheduleToCloseTimeoutSeconds=255l ) } You'll notice the l (as in Long) on the time out parameter. Cadence throws a fit when it sees it, as it expects an integer. Anyone know a way to get rid of the 'l' literal qualifier when gen-class compiling?

noisesmith21:04:52

in clojure, 100 has type Long, you can use (int 100) to create an Integer

KJO21:04:18

Thanks. I tried that, but running compile throws Unexpected error (ClassCastException) macroexpanding clojure.core/gen-interface

noisesmith21:04:16

is there a stack trace with more detail? (in a repl you can use *e to see the last exception)

KJO22:04:42

This is what I get

KJO22:04:42

#error {
 :cause "class clojure.lang.Var cannot be cast to class java.lang.Class (clojure.lang.Var is in unnamed module of loader 'app'; java.lang.Class is in module java.base of loader 'bootstrap')"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "Unexpected error macroexpanding clojure.core/gen-interface at (cdnce/cactivity.clj:6:1)."
   :data #:clojure.error{:phase :macroexpansion, :line 6, :column 1, :source "cdnce/cactivity.clj", :symbol clojure.core/gen-interface}
   :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 7019]}
  {:type java.lang.ClassCastException
   :message "class clojure.lang.Var cannot be cast to class java.lang.Class (clojure.lang.Var is in unnamed module of loader 'app'; java.lang.Class is in module java.base of loader 'bootstrap')"
   :at [clojure.core$descriptor invokeStatic "core.clj" 5460]}]
 :trace
 [[clojure.core$descriptor invokeStatic "core.clj" 5460]
  [clojure.core$add_annotation invokeStatic "core.clj" 5476]
  [clojure.core$process_annotation invokeStatic "core.clj" 5485]
  [clojure.core$add_annotations invokeStatic "core.clj" 5500]
  [clojure.core$add_annotations invokeStatic "core.clj" 5489]
  [clojure.core$generate_interface invokeStatic "genclass.clj" 674]
  [clojure.core$gen_interface invokeStatic "genclass.clj" 688]
  [clojure.core$gen_interface doInvoke "genclass.clj" 688]
  [clojure.lang.RestFn applyTo "RestFn.java" 142]
  [clojure.lang.Var applyTo "Var.java" 705]
  [clojure.lang.Compiler macroexpand1 "Compiler.java" 6993]
  [clojure.lang.Compiler analyzeSeq "Compiler.java" 7093]
  [clojure.lang.Compiler analyze "Compiler.java" 6789]
  [clojure.lang.Compiler analyze "Compiler.java" 6745]
  [clojure.lang.Compiler$BodyExpr$Parser parse "Compiler.java" 6118]
  [clojure.lang.Compiler$LetExpr$Parser parse "Compiler.java" 6436]
  [clojure.lang.Compiler analyzeSeq "Compiler.java" 7107]
  [clojure.lang.Compiler analyze "Compiler.java" 6789]
  [clojure.lang.Compiler analyze "Compiler.java" 6745]
  [clojure.lang.Compiler$BodyExpr$Parser parse "Compiler.java" 6120]
  [clojure.lang.Compiler$FnMethod parse "Compiler.java" 5467]
  [clojure.lang.Compiler$FnExpr parse "Compiler.java" 4029]
  [clojure.lang.Compiler analyzeSeq "Compiler.java" 7105]
  [clojure.lang.Compiler analyze "Compiler.java" 6789]
  [clojure.lang.Compiler analyze "Compiler.java" 6745]
  [clojure.lang.Compiler$InvokeExpr parse "Compiler.java" 3820]
  [clojure.lang.Compiler analyzeSeq "Compiler.java" 7109]
  [clojure.lang.Compiler analyze "Compiler.java" 6789]
  [clojure.lang.Compiler analyze "Compiler.java" 6745]
  [clojure.lang.Compiler$LetExpr$Parser parse "Compiler.java" 6346]
  [clojure.lang.Compiler analyzeSeq "Compiler.java" 7107]
  [clojure.lang.Compiler analyze "Compiler.java" 6789]
  [clojure.lang.Compiler analyze "Compiler.java" 6745]
  [clojure.lang.Compiler compile1 "Compiler.java" 7726]
  [clojure.lang.Compiler compile "Compiler.java" 7798]
  [clojure.lang.RT compile "RT.java" 411]
  [clojure.lang.RT load "RT.java" 457]
  [clojure.lang.RT load "RT.java" 424]
  [clojure.core$load$fn__6839 invoke "core.clj" 6126]
  [clojure.core$load invokeStatic "core.clj" 6125]
  [clojure.core$load doInvoke "core.clj" 6109]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [clojure.core$load_one invokeStatic "core.clj" 5908]
  [clojure.core$compile$fn__6844 invoke "core.clj" 6136]
  [clojure.core$compile invokeStatic "core.clj" 6136]
  [clojure.core$compile invoke "core.clj" 6128]
  [cdnce.cactivity$eval7542 invokeStatic "NO_SOURCE_FILE" 31]
  [cdnce.cactivity$eval7542 invoke "NO_SOURCE_FILE" 31]
  [clojure.lang.Compiler eval "Compiler.java" 7177]
  [clojure.lang.Compiler eval "Compiler.java" 7132]
  [clojure.core$eval invokeStatic "core.clj" 3214]
  [clojure.core$eval invoke "core.clj" 3210]
  [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437]
  [clojure.main$repl$fn__9095 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl doInvoke "main.clj" 368]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 79]
  [nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
  [nrepl.middleware.interruptible_eval$interruptible_eval$fn__800$fn__804 invoke "interruptible_eval.clj" 142]
  [clojure.lang.AFn run "AFn.java" 22]
  [nrepl.middleware.session$session_exec$main_loop__901$fn__905 invoke "session.clj" 171]
  [nrepl.middleware.session$session_exec$main_loop__901 invoke "session.clj" 170]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.lang.Thread run "Thread.java" 834]]}

KJO22:04:15

I've tried ' and `

KJO22:04:10

too to see if I could convince the compiler to not interpret the number and just pass it as is. The compiler doesn't like that either.

noisesmith22:04:05

it's the reader that makes 100 a long

noisesmith23:04:40

putting an integer instead of a long into the input of gen-class might require a macro...

noisesmith23:04:34

since gen-class is a macro, and it appears it doesn't evaluate the (int 100) form

emccue23:04:17

~`(int 100) perhaps

KJO23:04:32

Thanks. I’ll try that and see what happens. ILYK.

KJO14:04:40

Nope. Can't get the annotation to work. Tried (int) .parseInt ' ` etc. I even tried declaring an enum in a java file, compiled and imported it - no joy. There is a workaround for my particular situation using an available builder in cadence. The code is ugly enough as it is, a little more inelegance can't hurt 🙂. Thanks anyway all.

noisesmith16:04:55

did you try a macro? that's the one thing that would work if calling int directly in the form doesn't

KJO16:04:30

Thanks. But, wouldn't the purpose of the macro to be replacing the macro call site with the symbol 100? Am I missing something?

noisesmith16:04:09

no, the symbol 100 is turned by clojure into the long 100

noisesmith16:04:26

a macro can insert the integer 100 into the resulting form, there's no other way to do that

noisesmith16:04:51

(in non-macro contexts (int 100) expands to an int, but in a macro it's just a list...)

noisesmith16:04:22

this is what they call "macro contagion" - to add functionality to a macro you'll usually need... another macro

KJO16:04:07

Aaah. Got it. Thanks. I'm so annoyed with it that I'll stick with the late-stage builder approach and then go back to it all later, when something else bite me in the butt - which it will. Thanks again.