This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-07
Channels
- # announcements (38)
- # asami (14)
- # beginners (35)
- # biff (3)
- # calva (29)
- # cider (20)
- # clj-kondo (7)
- # cljdoc (38)
- # clojure (64)
- # clojure-art (2)
- # clojure-australia (1)
- # clojure-dev (6)
- # clojure-europe (30)
- # clojure-nl (4)
- # clojure-spec (4)
- # clojure-uk (9)
- # clojured (3)
- # clojurescript (87)
- # cursive (17)
- # datahike (2)
- # datomic (10)
- # defnpodcast (2)
- # emacs (2)
- # events (1)
- # fulcro (25)
- # gratitude (1)
- # introduce-yourself (1)
- # jobs-discuss (21)
- # lsp (103)
- # malli (41)
- # meander (8)
- # minecraft (3)
- # missionary (3)
- # nextjournal (20)
- # off-topic (10)
- # pedestal (1)
- # polylith (15)
- # portal (6)
- # releases (2)
- # ring (1)
- # ring-swagger (2)
- # sci (4)
- # shadow-cljs (5)
- # spacemacs (3)
- # sql (11)
- # xtdb (3)
Hi! cli with subcommands - preferrably working with babashka. cli-matic might do the trick. Any other suggestions?
@U06FLL69W I'm using docopt with babashka for dev tasks for rewrite-clj. I wrapped it to be more task usage oriented than command line usage oriented.
Just wanted to point out you can do this with tools.cli too using https://github.com/clojure/tools.cli#in-order-processing-for-subcommands
Do the testing
macros in have any purpose other than documentation? I initially thought of them as blocks similar to rspec where tests have "narratives" but they can't be used for that without allowing bindings
Purely documentation.
Hello, all! How to check memory consuption in JVM if I do?
(def ba (very-large-byte-array))
(byte-array (drop 15 ba))
I need to skip first 15 bytes from ba, and then apply the rest of ba to java function. I'm seeking the most effective way to do that from point of RAM consumption.seq version will likely require more intermediate allocation, copyOfRange should be a JVM intrinsic (though not 100% on that) that just allocates the new array up front
Thank you. I'm already implemented my solution using java.util.Arrays/copyOfRange but I'm interested to compare seq vs copyOfRange versions and how to see memory consumption in JVM?
You could try visualvm https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/profiler.html or yourkit https://www.yourkit.com/docs/java/help/memory_telemetry.jsp
in either case the resultant byte array will be the same size on the heap, the only difference will be in intermediate allocations to create the copy.
the intermediate collections will be garbage collected as you go so really the impact will be felt in the time it takes to copy
Thank you. I'll take VisualVM to see it.
if I have 1 000 000 array, then Arrays/copyOfRange makes new array of the same size minus 15 bytes. so it is O(n) solution.
I thought that seq
may be lazy and I can use this property to consume more effectively the rest of array. e.g. apply fn to current array but starting from 15th byte and not to copy it to another almost the same size.
when you call (byte-array seq)
you will realise the entire sequence and allocate an array with the same size as the seq.
it might help if we knew the use case because it may be you do not need to allocate a byte-array at all, in which case the seq version (or something else) may be better
but if you need a new array which is a slice of another one copyOfRange is the best you can get afaik
My case: I have encrypted data in bytes buffer [header, data]. I need to read header, make header analysis, then decrypt data (skip 15 bytes of header). I need to do it in a most effective way cause buffers can be large.
I can take any option
it is a clojure wrapper function on Bouncycastle java function, so signature is (decrypt-bytes ^Cipher cipher ^bytes encrypted-buffer)
Or to be effective we should wait for Project Valhalla? 🙂 (to apply fn to byte-array starting from nth position)?
I changed my solution to read by 1024 bytes and decrypt step by step without memory consumption.
how about just left shifting 30 bits https://clojuredocs.org/clojure.core/bit-shift-left
I think this is not for large buffers
you can then slice the buffer and pass it to a Cipher. (Be careful using BouncyCastle, it is a very error prone library)
oh, thank you. where I can read about errors in BC ? I need some investigation for my cases.
only gost. I’m working on wrapper for Clojure for Gost
(the general topic here is called 'misuse resistance' -- aka use google/tink rather than a low level swiss-army knife style library, such as BC)
Peculiarities of floating point operations. I believe this section explains it: https://en.wikipedia.org/wiki/Floating-point_arithmetic#Representable_numbers,_conversion_and_rounding
TL;DR is that decimal numbers are generally only approximate in nearly all languages. In Clojure you can get precise results using rationals (+ 1/2 1/10 3/10)
or BigDecimals (+ 0.5M 0.1M 0.3M)
, but both of these come with some more overhead that might matter if you're doing a lot of number crunching.
Also, between those, BigDecimals are of course only precise for things with a closed decimal form (e.g., 1/3 will still have some imprecision as a BigDecimal), and both are imprecise for anything that isn't rational (e.g., the square root of 2).
congrats eelke, you just found one of the monsters at the bottom of computing! floating point maths is neither commutative nor associative!
Here are some compensated summation algorithms you can use to limit the error accumulation if you're adding many numbers : https://github.com/sicmutils/sicmutils/blob/main/src/sicmutils/series.cljc
kahan-babushka-neumaier is the one to use usually
Hi there
Im wondering if Clojure has an optimization for empty maps - when I write {}
, is a new map created or some static empty map referenced?
Indeed, the singleton clojure.lang.PersistentArrayMap.EMPTY
is used.
You can double-check by calling (System/identityHashCode {})
multiple times.
Cool, thank you!
@ggfpc12495 sequence is an ordered notion. But it really depends on if you can rely on the order of the underlying producer of a lazy sequence. What’s the source?
It also depends on what the question means. It can mean "order of subsequent iterations over the same collection" - and if so, then the answer is "yes, you can rely on it."
I have an endpoint that receives a list of Json objects. In my handler I map a bunch of functions over each element of the list and return it. Can I trust that the output is in the same order as the input?
using map and similar operations are single-threaded and operate on the sequence in the order they are received in, so yes, the order will always match the source.
The thing to be careful of is that maps and sets don't have any guarantees about their order remaining consistent when new items are added or old ones removed, or even with the same set of items that the order will be consistent across runs of the JVM or on different JVMs.