Fork me on GitHub
#beginners
<
2019-04-03
>
tabidots02:04:11

I am trying to build some basic functions to manipulate polynomials. Is there a conventional way to implement a function that maps over collections but pads shorter ones with a fill value? Or just one that is perhaps more clever or concise or elegant than this? ↓ Just feel like I’m applying all over the place.

dpsutton02:04:56

Maybe you could represent polynomials as maps rather than sequences? Then your polynomial add just becomes merge-with +

tabidots02:04:48

Ah, I like that. With the powers as keywords? Like (merge-with + {:0 1 :1 4 :3 19} {:1 7 :3 2 :5 3})?

hiredman02:04:42

don't make keywords like that

hiredman02:04:09

numbers are perfectly fine keys

tabidots02:04:31

Ah, right, with numbers as keys, I can do this:

archibald.pontier_clo06:04:02

Hi, I'm trying to use the follow java library https://github.com/robert-bor/aho-corasick in clojure

archibald.pontier_clo06:04:24

I added (:import [org.ahocorasick.trie Trie Emit] to my code, but I don't understand how to actually build a Trie. I tried (.builder Trie), or (-> Trie .builder) and others

rahul08032706:04:54

@ the builder is a static method in the class and can be accessed like this: (Trie/builder)

rahul08032706:04:47

(-> (Trie/builder) (.addKeyword "hers") ... (.build))

archibald.pontier_clo06:04:24

Thank you very much!

c09mld08:04:49

@jarvinenemil Thanks for the offer, thought I managed to track it down myself

twaima12:04:31

can you REPL into an already working application?

joelsanchez12:04:59

@twaima if you execute lein repl you will see smth like this:

nREPL server started on port 35043 on host 127.0.0.1 - 
copy that port and lein repl :connect localhost:35043 to connect to that repl

twaima12:04:42

can I have 2 REPLs into same app?

joelsanchez12:04:26

you can connect as many clients as you want to an nREPL server (within reason)

twaima12:04:28

is it common to have an app in production with nREPL enabled?

joelsanchez12:04:07

it's not unheard of although I don't think it's common practice. I find it useful for debugging production issues

joelsanchez12:04:51

just don't expose it to the internet 😛

twaima12:04:49

Internet would like it 😂

andrew51314:04:13

I'm building a toy project with Fulcro to learn clj/cljs. I'm thinking about what database to back it with. Trying out Datomic seems like to good idea to immerse myself in clojure-y thinking. The issue here is I don't really understand the difference between the free and "1 year free pro" versions. It seems the free version only has an older API that isn't recommended for use anymore. Is that accurate? What would you choose for a toy project?

manutter5114:04:28

For a toy project, I might consider datahike https://github.com/replikativ/datahike

manutter5114:04:49

it’s not datomic but it’s a datalog-based db like datomic is, so you’d get a lot of the “immerse myself in clojure-y thinking” bit.

andrew51314:04:36

Thanks for the link! Looks interesting and potentially a lot easier to set up and work with. My other option is to just go with monger as I already have a mongo database with some real world data in it. That might be a pain due to the data being designed for a different app however. In your opinion is it worth it to spend time learning datomic/datalog?

manutter5114:04:13

I would say so, but I’m biased in favor of learning new stuff all the time 😉

manutter5114:04:09

also, there’s value in learning the Mongo/Clojure interface too, so :man-shrugging:

andrew51315:04:04

I'm with you on the learning new stuff all the time 😀 I got started on this clojure(script) kick while searching for solutions to problems in my large typescript project

andrew51315:04:21

I got sucked in by Hickey's "simple made easy" talk haha

manutter5115:04:22

That’s one of my favorite talks.

twaima16:04:21

please suggest good resources to learn core.async 🙂

dpsutton16:04:48

tim baldridge has some youtube videos on it i think

dpsutton16:04:04

he has a great pedagogical style as well

dpsutton16:04:48

also, this is paid but i think worth the $3 or $4 a month: https://tbaldridge.pivotshare.com/ He has 21 core.async videos there

aryyya.xyz18:04:29

Is this the best way to append an element to a sequence?

(concat sequence [element])
The confusing part for me is why there isn’t a way to append a single element to the end of a sequence so that I don’t have to wrap the element in a vector to use concat. The code I’m using this in is my implementation of map and filter defined in terms of reduce:
(defn reduce-map
  [function collection]
  (reduce
   (fn [accumulator element]
     (concat accumulator [(function element)]))
   '()
   collection))

(defn reduce-filter
  [predicate collection]
  (reduce
   (fn [filtered element]
     (if (predicate element)
       (concat filtered [element])
       filtered))
   '()
   collection))

noisesmith18:04:17

that's basically mapv...

lennart.buit18:04:12

yep, point taken, I’ll remove the snippet to reduce confusion!

lennart.buit18:04:12

oh, I was actually helping :’). The question was implementing map & filter in terms of reduce

noisesmith18:04:33

haha, OK - context!

lennart.buit18:04:05

haha, you made me feel real stupid :’)

noisesmith19:04:33

oh ... not trying to do that to anybody

lennart.buit19:04:55

oh no not implying that! Nuance gets lost over the internet ^^!

lennart.buit18:04:32

uhh yeah you are right — I was solving the question instead of the problem ^^

lennart.buit18:04:11

so in that particular case it would be (mapv (fn [element] (function element)) collection). That said, its still valuable to know that conj uses the most sensible insertion order.

mbjarland18:04:50

Slack usage/code of conduct question, if there is a subject specific channel but it is very infrequently in use, should you still wait for responses there or can you ping the main clojure or this channel with one off questions

manutter5119:04:50

I know I've found out about some channels because people posted "Hey, I have a question about Fooness over in the #fooness channel, could someone have a look?"

manutter5119:04:36

I wouldn't cut and paste the question back into the main channel because sometimes that fragments the discussion and makes it hard to follow, but that may be just a personal preference.

manutter5119:04:24

But I think a brief ping now and then is fine (Disclaimer: I'm not an admin, just sharing my personal preferences.)

mbjarland19:04:19

Right, maybe I'll let the question marinate in the specific channel for a bit and see where it lands. Thanks for the feedback

seancorfield20:04:03

@mbjarland Which channel wasn't getting you a response? (maybe we can suggest a more active channel that might also help)

mbjarland10:04:07

This was on #datomic - really the question was about ions and whether ions are suitable for a plain-vanilla ring-type web applications or aimed at api:s and event handlers. I posted it on #clojure after...

seancorfield17:04:37

Ah... I would have expected #datomic to be the best place to ask... sorry you didn't get a response there 😞