Fork me on GitHub
#beginners
<
2021-07-29
>
ChillPillzKillzBillz07:07:31

noob question: If I've got a nested map structure... like so : {:top {:name "blah" :data {:entry1 "asdf" :entry2 "asdf"}}} Is there a way of accessing the entry2 value like in other languages...? e.g. in python it'll accessed by <mapname>[top][data][entry2]. The clojure notation that I've figured out so far is a lot of nested :keyname calls to the map... (:entry2 (:data (:top <mapname>)))

domparry10:07:24

(get-in <mapname> [:top :data :entry2])

phronmophobic07:07:20

the "thread first", -> macro is commonly used for this

(-> my-map :top :data :entry2)

ChillPillzKillzBillz07:07:51

Is there anything better than threading? This is why I was investigating the double colon notation, hoping that it'll help with resolving nested maps... but thanks for your help!

seancorfield07:07:32

<mapname>[top][data][entry2] and (-> my-map :top :data :entry2) look very, very similar to me.

seancorfield07:07:52

(and I prefer the latter due to "less syntax noise")

seancorfield07:07:40

I think this is just a matter of familiarity. The more you use Clojure, the more natural this will seem to be (and the more ugly/verbose other languages will look).

phronmophobic07:07:46

It's definitely one of those things where I thought the threading macro was this really weird thing when I first saw clojure, and now I get really annoyed when I try to write js or python 🤷

ChillPillzKillzBillz07:07:04

it is definitely hard to wrap my head around the threading macro as my head is still thinking in C/python

ChillPillzKillzBillz07:07:14

practice makes perfect ... I guess

phronmophobic07:07:22

yea, I remember the threading macros being pretty jarring at first, but they grow on you after a while.

👍 3
phronmophobic07:07:25

They're a little more flexible than the bracket syntax and they tend to work more universally in clojure since almost everything is immutable and returns a value. You don't have to go out of your way to write your api to return its value: eg. builder().addThing("asdf").timeout(10).execute().after(cleanup)

zackteo07:07:36

Are there libraries I might want to look if I want to take a video like say an .mp4 file and produce pixelized colour data of the frame by frame images

pavlosmelissinos08:07:40

What's the recommended way to programmatically generate maps/edn that include custom tagged literals? Something like this:

{:db-spec {:host    #aws/ssm "/app/_/db/env/host"
           :db-name #aws/ssm "/app/_/db/env/db-name"
           :user    #aws/ssm "/app/_/db/env/username"
           :pass    #aws/ssm "/app/_/db/env/password"}}
In particular, is there a way than doesn't directly involve string manipulation?

delaguardo09:07:51

{:db-spec {:host (tagged-literal 'aws/ssm "/app/_/db/env/host")
           :db-name (tagged-literal 'aws/ssm "/app/_/db/env/db-name")
           :user (tagged-literal 'aws/ssm "/app/_/db/env/username")
           :pass (tagged-literal 'aws/ssm "/app/_/db/env/password")}}

pavlosmelissinos09:07:14

That seems to work (with a small modification):

(tagged-literal 'aws/ssm "/app/_/db/env/password")
  => #aws/ssm/app/_/db/env/password

  (tagged-literal 'aws/ssm " \"/app/_/db/env/password\"")
  => #aws/ssm "/app/_/db/env/password"
Thanks a lot, that's exactly what I need 🙂

delaguardo09:07:52

user=> (tagged-literal 'aws/ssm "/app/_/db/env/password")
#aws/ssm "/app/_/db/env/password"
are you sure this modification is needed?

pavlosmelissinos09:07:48

Weird, it's not working like that on my end

delaguardo09:07:02

strange. tagged-literal is a function of two arguments. Could it be a problem of the editor?

delaguardo09:07:44

works just fine in sublimetext

pavlosmelissinos09:07:46

Oh, I'm an idiot... I was in a clojurescript namespace/repl before, sorry. It works fine in clojure!

ChillPillzKillzBillz10:07:28

I would like to practice creating some programs in clojure... is there a puzzle book which forces one to think in clojure ways? ... I know... I am silly that way... 😁

schmee11:07:24

try https://www.4clojure.com/! try to solve problems and after you’ve solved them look at other people’s solutions, that was a huge eye-opener for me when I started out

schmee11:07:51

(there seems to be some certificate issue with the site, but it expired just a few days ago so I’m sure they’ll fix it soon)

ChillPillzKillzBillz13:07:51

this site doesn't work for me. FYI

borkdude13:07:54

@U022LK3L4JJ 4clojure is shutting down, but @U013MQC5YKD has made a CLJS replacement here: https://4clojure.oxal.org/

sova-soars-the-sora15:07:44

There's also Clojure Koans

Andrew Berrien16:07:29

I figured something was up with 4clojure because it's been giving that outdated certificate error for a while now...

Fahd El Mazouni13:07:36

Hello Hello everyone ! Is there a "clean" way to use a higher version of java library that is also a transient dependency of another package ? (using the newer version breaks the package)

schmee14:07:10

what tool are you using to manage deps? lein? deps.clj?

Fahd El Mazouni14:07:13

we're using lein ! to be specific we use dk.ative/docjure that has a dependency on org.apache.poi, I'd like to use that library directly to work with charts (no support for that in the clojure library)

indy14:07:15

[dk.ative/docjure <version> :exclusions [org.apache.poi/poi]]
[org.apache.poi/poi <version>]
Should work unless docjure specifically depends on that particular version of org.apache.poi/poi

Fahd El Mazouni14:07:46

yeah I think it does depend on 4.1.1 specifically, a colleague told me that, I'll just check myself to confirm.

Fahd El Mazouni14:07:58

yep it does break with a higher version

Fahd El Mazouni14:07:21

I'm looking at https://github.com/benedekfazekas/mranderson right now, but if you have any other suggestions they would be much appreciated ! thanks for your help !

Jakub Šťastný16:07:33

What's the best way to check whether there's something in an atom in a non-blocking style? (deref a 100 :timeout)?

Russell Mull16:07:40

Atom reads are not blocking; just use deref or @ and you're good to go.

emccue16:07:04

if you want a thing that you wait for a result on on a max delay, you probably want a promise

Jakub Šťastný16:07:35

Ah I see! Thanks!

emccue16:07:24

that or a chan

emccue16:07:30

(if you include core async)

Jakub Šťastný17:07:55

I have two futures running at the same time. Currently (as a hack) I use (Thread/sleep n) so the main thread wouldn't quit, which is what happens without it, the main thread quits immediately without the futures actually ever finishing. How do I I wait for both of these futures to finish before quiting?

dpsutton17:07:34

(run! deref [fut1 fut2])

👍 3
3
Russell Mull17:07:52

That was a really interesting question, but it's gone now 😕

dpsutton17:07:01

effectively no. (length of function names). It seems classfile names are limited to 65535 characters. So the munged namespace and function name cannot exceed that.

🎯 3
Russell Mull17:07:11

For posterity: someone asked what is the maximum length of a function name

Russell Mull17:07:10

I couldn't find a limit either, to speak of. It seems likely that you'll run into file name length limitations before anything else.