This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-12
Channels
- # babashka (4)
- # beginners (49)
- # biff (17)
- # calva (12)
- # cider (5)
- # clojure-czech (1)
- # clojure-europe (3)
- # clojure-norway (3)
- # core-logic (1)
- # cursive (4)
- # data-science (2)
- # datalevin (7)
- # emacs (1)
- # events (6)
- # fulcro (11)
- # helix (7)
- # hyperfiddle (30)
- # lsp (4)
- # podcasts-discuss (1)
- # practicalli (4)
- # releases (1)
- # remote-jobs (7)
- # ring (6)
- # spacemacs (4)
- # tools-deps (5)
hi everyone, i have a question about the effects of conj
in the context of constructing a 2D vector from Java arrays. Specifically, I wrote a function that iterates over an image stack and then grabs a reference to a Java array at each step—representing pixel values for the ith image slice—and appends it to a vector.
(defn get-pixels-arrays [imgStack]
(loop [i 1 v []]
(if (<= i number-of-slices)
(recur (inc i) (conj v (-> imgStack
(.getProcessor i)
(.getPixels)
)))
v)))
;; calling the function on an image stack of size 32
(def inputImageArray (get-pixels-arrays inputImageStack))
;; returns 32
(count inputImageArray)
But after creating the vector, I cannot grab individual elements of the nested array and get a value of 1 from count
when I apply it to any one of the nested arrays.
(count (take 1 inputImageArray)) ;; returns 1 instead of 262144
(take 5 (take 1 inputImageArray)) ;; returns the entire array instead of the first 5 elements.
This behaviour seems to be an artefact of using conj
because when I use take
and count
directly on the array, they work fine:
(def test-array (-> inputImageStack
(.getProcessor 1)
(.getPixels)))
(count test-array) ;; returns 262144
(take 5 test-array) ;; returns first 5 elements
Could someone help me understand what is going on? Thank youSo maybe double check that the code you think is running is actually what is running (restart your repl, verify your code loads without errors, etc)
it is present in my code. i have checked the value, it is 32.
(def number-of-slices (.getSize inputImageStack))
How sure are you that the function you are calling is the function source you are looking st
i am using calva on VS code and i re-evaluate the function every time i make a change.
If you put (println "hello world")
at the top of the function does it print when you call the function
And then you can see if it is the same as the count when you pull it out of the vector
In Python there's a built-in function help
available in the REPL that when provided a function, it opens up documentation of that thing, like a man page.
Is there something similar to that in Clojure?
things I'm interested to see in the documentation: • the docstring (if available, of course) • usage examples (the ones on ClojureDocs are really useful)
Which editor are you using? I think both Emacs (with CIDER) and VS Code (with Calva) will show you docstrings, clojuredocs examples, and individual argument names etc, while you are typing or via a hot key.
Hi, did you check https://clojuredocs.org/clojure.repl/doc ?
Docstring, arglists, and jump-to-definition should be supplied by the IDE (as well described in the https://lambdaisland.com/blog/29-12-2017-the-bare-minimum-clojure-mayonnaise). For usage examples I have a Firefox search term set up so "clj juxt" goes to https://clojuredocs.org/search?q=juxt though I'm trying to switch to cider-clojuredocs
.
Tupelo library says it has an unwrap function in the documentation: https://cljdoc.org/d/tupelo/tupelo/23.05.31/doc/readme#_combining_scalars_and_vectors However I can't seem the find the function anywhere in the code: https://github.com/search?q=repo%3Acloojure%2Ftupelo+unwrap&type=code I am also getting errors with the latest version not recognizing this function.
Syntax error compiling at (src/dave/notebooks/evdev.clj:6:49).
Unable to resolve symbol: unwrap in this context.
Anyone know what might be going on here?This is where git's "pickaxe" can come in handy. A quick search makes me think it was renamed to <>
https://cljdoc.org/d/tupelo/tupelo/23.05.31/api/tupelo.core#%3C%3E
The fact that nearly every commit in that repo is titled "misc" doesn't speak particularly well for it imo, and no doubt makes this sort of search harder
Hmm, after playing around with it, I think they split the functionality between <>
and the only
.
I thought Tupelo was a pretty popular library. I kinda felt left out not using it.
> I thought Tupelo was a pretty popular library. For what it's worth, I've heard of it but no team I've worked with has used it
Tupelo's author was prolific on StackOverflow and answered many, many questions correctly and helpfully and with a plug for Tupelo. This may have bolstered an impression of Tupelo's wide popularity.
Hi there! I have two lists, be it localmails
and remotemails
. Make both be {:email value :attribute attr :attribute2 attr ...}
. I need to split localmails
in three lists: New, Updated, Deleted by comparing with remotemails
, that is: see what entries are not in the remote list, which have different attributes, which are on remoteemails
but not in localmails
.
Could someone point me in the right direction? Like the names of the functions I wan't to learn about 🙂 thx
this could likely be accomplished with something like a reduce that does a comparison and adds to an output map, or potentially with the clojure.set
namespace, if those lists can be transformed into sets (relations) and join
ed to produce one output set
alternatively, it's likely possible to use something like clojure.data/diff
to do an initial separation (eliminate the equal ones), and then pare down to just the emails and diff them
Nice, diff
looks exactly right. That would give me the three lists, then I'll just have to see the Updated list for changes. Thanks for the tip!
For anyone looking, what I have done is:
1. Use set/join
to get a single list of all items (I join via :email). There are no duplicate keys on either map which is ok.
2. filter
to exclude the ones which the remote ID is nil -- aka: New items, CREATED
3. filter
to exclude the ones which the local ID is nil -- aka: Gone items
4. use (difference ...)
with the three sets above to get the "maybe updated" which I then pass through another function to compare fields and return a map of updates to do
thx @U013JFLRFS8 for the pointers!