This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-16
Channels
- # announcements (1)
- # babashka (23)
- # beginners (157)
- # boot (3)
- # calva (2)
- # chlorine-clover (12)
- # cider (14)
- # clara (5)
- # clj-kondo (6)
- # cljs-dev (61)
- # cljsrn (30)
- # clojure (65)
- # clojure-argentina (8)
- # clojure-berlin (2)
- # clojure-europe (13)
- # clojure-france (9)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-nl (6)
- # clojure-portugal (2)
- # clojure-romania (2)
- # clojure-uk (76)
- # clojurescript (56)
- # conjure (52)
- # core-async (37)
- # datomic (209)
- # duct (17)
- # emacs (17)
- # exercism (1)
- # fulcro (26)
- # graalvm (5)
- # instaparse (2)
- # jackdaw (9)
- # jobs-discuss (27)
- # joker (2)
- # juxt (23)
- # leiningen (4)
- # malli (11)
- # midje (3)
- # pedestal (2)
- # quil (2)
- # re-frame (78)
- # reagent (8)
- # reitit (18)
- # remote-jobs (1)
- # ring (2)
- # ring-swagger (1)
- # shadow-cljs (29)
- # sql (11)
- # test-check (12)
- # tools-deps (5)
- # xtdb (16)
- # yada (4)
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
thanks, that works !
just for my understanding, how does the above regex differ from this one #"[(),]|:-" "")
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
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?
it's a command line jvm flag - see https://www.logicbig.com/tutorials/core-java-tutorial/modules/illegal-access-operations.html
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 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.
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?
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
Yeah, it's really nice
i’m also in the middle of trying to speed up some code. this is a great resource. thanks for sharing :thumbsup:
depending on what you're doing, transducers may be faster than seqs
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
Thanks, I'll look into that! There are a lot of consecutive filters happening 👍
You can parallelize them using reducers, for example https://clojure.org/reference/reducers
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 👍
Is there any overhead with multi-arty functions?
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
That makes sense, thanks!
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?
Is there a way for instance to patch a var to make it dynamic?
Follow ups in #core-async please...
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.
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
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
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)
#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]]}
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
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