Fork me on GitHub
#beginners
<
2017-08-07
>
dfcarpenter02:08:37

Hi everyone, im looking into web scraping with clojure and I have some basic things working with enlive but i'm trying to figure out how to do things like form submissions and deal with dynamic javascript. Any suggestions?

gonewest81802:08:36

You're going to need an actual JavaScript engine ... PhantomJS?

clumsyjedi05:08:59

user=> (conj '(1 2 3) 4)
(4 1 2 3)
user=> (cons 4 '(1 2 3))
(4 1 2 3)
What do I actually have to do to produce '(1 2 3 4)`

bnvinay9206:08:15

(let [numbers '(1 2 3)] (apply list (conj (vec numbers) 4)))

clumsyjedi06:08:36

thanks @bnvinay92 that's roughly what I had, I wasn't sure if there was a better way

leira08:08:36

@akiroz thanks for the reply. I meant, add-and-get is not a defn, but a def, so ai is part of add-and-get this variable, rather than part of function body.

leira08:08:17

how to bind parameter which is not the first?

leira08:08:06

(def mod5 (bind mod _ 5))

schmee09:08:40

@clumsyjedi if you want to add efficiently to the end of a collection, use a vector instead:

user=> (conj [1 2 3] 4)
[1 2 3 4]

sb10:08:52

I have an indexed map like ([0 -12] [1 -5] [2 -137] [3 5] [4 32] [5 45]) and I would like to find every value with 5. But in this case I get the 45 too.. if that isn’t indexed map works everything fine.. (filter #(= (second %) 5) indexed-map)

sb10:08:44

I got back two positions ([3 5]) with value 45 too

sb10:08:00

why? could you help me, what is the logic?

sb10:08:15

what is the different at maps or indexed maps? (in this case)

schmee10:08:46

what do you mean with “indexed map”?

schmee10:08:52

the thing you posted above is a list of vectors

genmeblog11:08:30

this works for me well

(filter #(= (second %) 5) [[0 -12] [1 -5] [2 -137] [3 5] [4 32] [5 45] [6 5]])
;; => ([3 5] [6 5])

sb11:08:22

@tsulej yes, no problem.. I’m just tired. Sorry! 👍

sb11:08:09

I thought [3 5] is two position, not one k v. I don’t know why..

genmeblog11:08:53

good! np 🙂

leira12:08:55

Is there a standard function to take until converge? like (take-until-converge (100 50 20 10 10 10 10...)) -> (100 50 20 10)

leira12:08:21

the difference is, for take-while, the predicate only got the current element

leira12:08:43

for a take until converge, the predicate needs to take the last 2 elements

lepistane12:08:21

here is the situation i am making questionnaire i've got questions(variable amount based on topic) and answers (predetermined, input radio button, variable amount) which i am sending to the client how do i send id, value or whatever from that radio button to the server?

curlyfry12:08:00

@leira I don't believe there is such a function in the standard library

tbaldridge13:08:17

@leira you could probably do it with take-while after reductions

yonatanel13:08:39

@leira also maybe using reduced to terminate a reduce.

tbaldridge13:08:40

@leira try this for the "last two" bit (reductions (fn [[_ p] n] [p n]) nil (range 4))

stardiviner15:08:41

What does the @(...) mean in Clojure?

michaelwfogleman15:08:22

@stardiviner It is a reader macro that is equivalent to (deref (...))

noisesmith16:08:53

@stardiviner the thing to google is “destructuring”

stardiviner16:08:57

I only know that a symbol like :keys can be used as function to query data. But don't understand the upper style.

stardiviner16:08:17

@noisesmith Thanks. I will google it

noisesmith16:08:23

{:keys [foo]} {:foo “a”} -> now foo is bound to “a”

jeremys16:08:45

@stardiviner Hey mate the @ is a reader macro and the {:keys [...} {} in a let binding uses clojure destructuring capabilities. If you were to macroexpand you would get code along the line of

(let [status (:status (deref (http/get "")))]
  (= status 200))

aryzle18:08:28

hey everyone, trying to write my first clojure service, using Java interop to interface with Kafka and OrientDB, things are acting really weird though where sometimes my println or (info "log") show up and sometimes they don't, anyone ever have a problem with that? Ik this is very vague sorry

noisesmith19:08:41

@aryzle the most common cause of that symptom is printing from inside map or for

noisesmith19:08:56

remember that these are lazy, and don’t do anything if nobody touches their return value

noisesmith19:08:28

one of the hardest lessons in early clojure learning can be “for is not a loop, and you can’t count on anything lazy happening”

noisesmith19:08:54

of course I don’t know that this is your problem, but it’s common enough to speculate a bit

aryzle19:08:30

@noisesmith thanks man! that did get me before, but I just checked and I had a bunch of rogue Java processes and after killing them my next run of the program worked

noisesmith19:08:51

oh - they were probably stealing your kafka messages, eh?

aryzle19:08:51

not sure if this was a lein issue or Nightcode

noisesmith19:08:07

yup, that would do it

noisesmith19:08:52

my inclination more and more is to always broadcast (fan out) from kafka (that is, every client has a unique id), and then if only one client should act on a given message, use a separate logic for coordinating who claimed the message and a follow up in case someone else should retry etc.

noisesmith19:08:04

but that has to do with my job times being very high though