Fork me on GitHub
#beginners
<
2023-05-11
>
Zach00:05:47

Hello 🙂 I'm trying to get the max from a list: (apply max my-list) But, it's throwing a stackoverflow. Is there any easy way around this?

Zach01:05:40

I can write a loop but that seems overkill...

seancorfield01:05:46

How are you building my-list? This works in a REPL for me:

build=> (apply max '(123 234 128 236))
236

Zach01:05:58

It's a big list

Zach01:05:09

~10k items

seancorfield01:05:37

Are you constructing it with concat?

Zach01:05:43

(apply max (map foo data))

seancorfield01:05:56

And how are you constructing data?

Zach01:05:31

Ah it's being consed

seancorfield01:05:44

Bottom line: lazy sequences can build up a stack of evaluations so it's possible you are hitting that stack's overflow.

Zach01:05:25

Ok so a loop really would be best here

seancorfield01:05:00

Well, perhaps changing how you build data might be the best choice...

seancorfield01:05:28

...but switching to a loop and explicitly iterating over the lazy sequence might avoid the overflow.

Zach01:05:00

Actually I'm using mapv so I'm surprised the sequence is lazy

Zach01:05:18

Nvm, something else is going on 🙂

seancorfield01:05:46

Probably how you're building data as a lazy sequence...

craftybones01:05:54

A reduce perhaps?

craftybones01:05:01

(reduce max foo)

Zach01:05:04

It was an actual stackoverflow! There was a circular reference of function calls and it was blowing up on that line

skylize03:05:59

Is some kind of philosophical claim? A stack overflow is not "real" if it's caused by buildup of lazy eval frames?

Zach03:05:58

I believe those are stack underflows 😉

skylize22:05:48

Even more philosophical. Now we're talking about negative stack frames. :rolling_on_the_floor_laughing:

😂 2
dumrat09:05:23

Is there any clojure library for pinecone?

pavlosmelissinos09:05:00

I don't see one but Pinecone has an: 1. https://docs.pinecone.io/reference 2. https://docs.pinecone.io/docs/python-client (you can use libpython-clj to access that) 3. https://docs.pinecone.io/docs/node-client (you can use it via nbb/clojurescript) 4. There's also a https://github.com/pinecone-io/pinecone-java-client which you can use via interop. You could consider any of the above solutions.

delaguardo11:05:52

would be great to know what you expect from such library

Hagenek13:05:43

My computer has an alternative maven repository setup, so I try to specify some repos in deps.edn like this. But I still get the Error building classpath. Could not find artifact integrant:integrant:jar:0.8.0 in central (https://nexus.intern...). Any tips?

{:paths
 ["src/main"
  "src/test"]


 :mvn/repos {"central" {:url ""}
             "clojars" {:url ""}}

 :deps
 {org.clojure/clojure {:mvn/version "1.10.3"}
  ring/ring {:mvn/version "1.9.4"}
  integrant/integrant {:mvn/version "0.8.0"}
  environ/environ {:mvn/version "1.2.0"}
  metosin/reitit {:mvn/version "0.5.15"}
  clj-http/clj-http {:mvn/version "3.12.3"}
  ovotech/ring-jwt {:mvn/version "2.2.1"}}

 :aliases
 {:dev
  {:extra-paths ["src/dev"]
   :extra-deps {com.datomic/dev-local {:mvn/version "0.9.232"}
                ring/ring-mock {:mvn/version "0.4.0"}
                integrant/repl {:mvn/version "0.3.2"}}}}}

Bob B14:05:58

Where is nexus coming from? Is it configured as a proxy in maven settings? Or a mirror? The deps reference indicates that proxies (and some other things) are pulled from maven setup, so maybe it's getting a mirror configuration from there (a very speculative maybe)

👍 1
teodorlu14:05:03

Do you possibly have some custom java repositories configured somewhere in ~/.m2? This sounds familiar to something I've experienced in the past.

👍 1
Hagenek14:05:33

a mirror is setup in .m2/settings.xml yes! Can I get it to circumvent this and use the standard repo?

teodorlu14:05:39

Not sure! I think I just moved ~/.m2/settings.xml to ~/.m2/settings.xml.backup, then moved it back when I needed it next time.

👍 1
Hagenek14:05:34

That did the trick! Takker takker

❤️ 1
Hagenek14:05:15

Hmm now it can't find: Error building classpath. Could not find artifact com.datomic:dev-local:jar:1.0.243 in central (https://repo1.maven.org/maven2/)

teodorlu14:05:58

There were some changes to Datomic distribution recently: https://blog.datomic.com/2023/04/datomic-is-free.html I'd try asking in #C03RZMDSH and see what they say 🙂

🙌 1
Hagenek15:05:41

Ahh that one you have to install yourself, it's. not on clojars

👍 1
Donal H15:05:42

I am coming from Python, so I am finding that my lack of JVM/Java library knowledge is becoming my hurdle. Has anyone found some good resources that I should dive into?

Ben Sless15:05:48

Depends on your problem domain. What problem are you trying to solve

Donal H15:05:24

I typically deal with data munging and web back-end stuff. For backstory, I went to hit an api, found that it was gziped and then got into a fight with Readers versus Streams. I found clj-http solved that issue for me, but it revealed to me where my gaps were.

Ben Sless16:05:11

I see My personal experience is having no knowledge of java coming into Clojure, but it's fine, I just did a bit of googling and figured it out. The java ecosystem is full of Q&As and the core library's javadoc is informative. In the end you probably want to parse it into something meaningful (json?) and many libraries are happy accepting either a reader or input stream But there's some careful reading needed where you might expect things to "just work"

1
Donal H18:05:30

Thank you! I think I just get nervous when Java pokes its head out. I tossed my "Head First Java" book out ages ago and have been happier ever since.

1
Ben Sless18:05:42

Knowing java is absolutely not a requirement, but Clojure is hosted and it embraces the JVM, so knowing what an interface is and knowing your way around java.unil.* packages is very useful

Ben Sless18:05:08

Mostly just streams, readers for 90% of what you should know, not the whole thing

Donal H18:05:00

Oh, nice. I've found https://medium.com/swlh/understanding-java-streams-e0f2df12441f on Streams and it is making heaps of sense. Thanks for the nudge in the right direction.

jumar06:05:37

For more in depth stuff, Wellgrounded Java Developer is a great book

2
stopa13:05:04

One book I found really fun: https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601. I found it interesting because a) you learn a bunch about java's concurrency model, b) you learn about java.util.concurrent, which we often use in Clojure, and c) you learn about the footguns in Java, and find many new reasons to be thankful for Rich's design decisions

2
Donal H14:05:47

This is hugely helpful. I can't wait to dive into these book recommendations.

dumrat16:05:47

Hi, is there any lib/function I can use to split a long text into manageable pieces with an interface like mentioned here: https://docs.pinecone.io/docs/langchain#building-the-knowledge-base

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=400,
    chunk_overlap=20,
    length_function=tiktoken_len,
    separators=["\n\n", "\n", " ", ""]
)

pppaul17:05:08

what is long? can your string fit in memory, or are you working on stuff like gene sequences?