Fork me on GitHub

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.


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


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)


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.


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


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


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


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


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


Both RegExes work?


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 :-"


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


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


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

Ramon Rios12:04:35 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.


hello guys, I'm working to improve clojure tooling around gradle - specifically clojurephant and this issue . 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


Ah you already use clj-async-profiler

Michael J Dorian14:04:18

Yeah, it's really nice simple_smile


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

Alex Miller (Clojure team)14:04:21

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

Alex Miller (Clojure team)14: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 👍


You can parallelize them using reducers, for example


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


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?

Alex Miller (Clojure team)16:04:08

Follow ups in #core-async please...


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


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


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


As of tools.logging 0.6.0 (from February) you can provide a JVM option to force it to use a specific logger

👀 4

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?


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


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


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


This is what I get


#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')"
 [{: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 "" 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]}]
 [[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 "" 142]
  [clojure.lang.Var applyTo "" 705]
  [clojure.lang.Compiler macroexpand1 "" 6993]
  [clojure.lang.Compiler analyzeSeq "" 7093]
  [clojure.lang.Compiler analyze "" 6789]
  [clojure.lang.Compiler analyze "" 6745]
  [clojure.lang.Compiler$BodyExpr$Parser parse "" 6118]
  [clojure.lang.Compiler$LetExpr$Parser parse "" 6436]
  [clojure.lang.Compiler analyzeSeq "" 7107]
  [clojure.lang.Compiler analyze "" 6789]
  [clojure.lang.Compiler analyze "" 6745]
  [clojure.lang.Compiler$BodyExpr$Parser parse "" 6120]
  [clojure.lang.Compiler$FnMethod parse "" 5467]
  [clojure.lang.Compiler$FnExpr parse "" 4029]
  [clojure.lang.Compiler analyzeSeq "" 7105]
  [clojure.lang.Compiler analyze "" 6789]
  [clojure.lang.Compiler analyze "" 6745]
  [clojure.lang.Compiler$InvokeExpr parse "" 3820]
  [clojure.lang.Compiler analyzeSeq "" 7109]
  [clojure.lang.Compiler analyze "" 6789]
  [clojure.lang.Compiler analyze "" 6745]
  [clojure.lang.Compiler$LetExpr$Parser parse "" 6346]
  [clojure.lang.Compiler analyzeSeq "" 7107]
  [clojure.lang.Compiler analyze "" 6789]
  [clojure.lang.Compiler analyze "" 6745]
  [clojure.lang.Compiler compile1 "" 7726]
  [clojure.lang.Compiler compile "" 7798]
  [clojure.lang.RT compile "" 411]
  [clojure.lang.RT load "" 457]
  [clojure.lang.RT load "" 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 "" 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 "" 7177]
  [clojure.lang.Compiler eval "" 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 "" 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 "" 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 "" 22]
  [java.lang.Thread run "" 834]]}


I've tried ' and `


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.


it's the reader that makes 100 a long


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


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


~`(int 100) perhaps


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


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.


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


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


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


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


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


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


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.