Fork me on GitHub
#beginners
<
2015-12-07
>
trancehime01:12:47

@kyle_schmidt: you should use some kind of io methods on the :tempfile

trancehime01:12:32

it depends on what kind of processing you want to do

kyle_schmidt01:12:33

@trancehime: thanks! Im using get-in on the map to get the :tempfile. I want to process a csv so I want to: A) make sure the file is a csv. B) make sure that there is only one column in the file. C) the uploaded file should contain a column of URIs that I want to iterate through to make sure that they all return valid responses by submitting a get request to each. D) indicate the received response in the adjacent column. That's the big picture but I needed some help on the initial step. Continuing to work through my list but thank you for your help!

trancehime01:12:15

use :content-type to tell you whether the file is csv or not

trancehime01:12:36

compare MIME type basically

trancehime01:12:49

since you are processing a csv, you probably dont want to use slurp as i'm assuming the file could be some arbitrarily large size (not always, but could be)

trancehime01:12:39

incidentally, there is a thing as clojure-csv

trancehime01:12:16

Though it's probably not applicable in this case due you are file uploading already

trancehime01:12:02

So, you might just want to stick with reader from or something

trancehime01:12:08

(I started working with image upload a while back and that was a challenge for me to actually get at first, but it wasn't so bad once I got the hang of it)

kyle_schmidt02:12:03

@trancehime: Thank you so much! You've been a tremendous help!

trancehime02:12:23

np, I am also a beginner, so it is good if we can help each other

trancehime06:12:41

Anyone alive?

roelof06:12:06

yes, 3 persons, me , myself and I simple_smile

roelof06:12:12

helllo, trancehime, early bird or are you not a European

trancehime06:12:18

It's 1412 here

trancehime06:12:31

So... I'm not European

roelof06:12:56

it's here 7:14

andrut06:12:04

it's 14:13 here and I am European...

trancehime06:12:25

OK, I guess better response is I am not living in Europe

trancehime06:12:04

In any case, I'm a bit weirded out, why this input thing that I have set to {:type "number"} is still casting its input to a String

trancehime06:12:14

maybe it's because I haven't wrapped a 'form' object around it

trancehime06:12:43

yeah, weird... data is initialized as an int but when i modify it the value in the atom becomes a String

roelof06:12:50

very wierd

trancehime06:12:14

oh well, I just parse the input to an int

roelof06:12:17

happy for you but it is still wierd

trancehime06:12:24

Yeah it's pretty weird.

roelof14:12:04

one for myself now : I have this code ; https://www.refheap.com/112449

roelof14:12:34

but now I see this error message : Don't know how to create ISeq from: clojure.lang.Keyword

roelof14:12:46

can someone give me a hint where the error is

swizzard14:12:07

i think it's cause you're using conj wrong

swizzard14:12:12

i think you want assoc here

agile_geek14:12:16

@roelof: also you are showing var names in the loop which is bad practice. I.e. loop [list1 list1... is shadowing list1 outside the loop with list 1 inside the loop.

roelof14:12:16

oke, I thought I could use conj to add a item to a map

roelof14:12:39

@agile_geek: how can I do this more the clojure way then ?

roelof14:12:52

I need list1 and list2 in the loop

agile_geek14:12:36

@roelof: firstly you usually associate a key value pair into a map (as it's an associative data structure) using assoc map key value

agile_geek14:12:53

in the loop just give the symbols different names i.e. loop [l1 list1 l2 list2]... and then reference the values l1 and l2 inside the loop (unless you really want the original list1 or list2 unchanged in every recursion of the loop)

roelof14:12:13

no list1 and list2 changes

agile_geek14:12:56

ok so use different names as I've shown. Obviously add your acc {} into the loop binding too.

agile_geek14:12:35

I suspect Clojure is dealing with this OK but it's confusing to humans.

roelof14:12:50

I thought acc is added to the loop binding ???

kimsnj14:12:32

@rcanepa: Did you watch or received feedback on LispCast's videos on web development? I am tempted by both this one and the one on Om/Clojurescript.

agile_geek14:12:34

it is - I'm confusing you. In my code snippet I left it out by accident. Should read loop [l1 list1 l2 list2 acc {} ] ..

roelof14:12:18

so this is good code :

(defn my-zipmap
  [list1 list2]
  (loop
    [l1 list1
     l2 list2
     acc {} ]
    (assoc acc (first l1) (first l2))
      (recur (rest list1) (rest list2) acc))
  )  

agile_geek14:12:26

FYI - you can conj a key value pair into a map but it's more idiomatic to use assoc.

roelof14:12:17

then I wonder why my cursive repl will not work

agile_geek14:12:22

@roelof: it will run. Up to you to prove it does what you need. Try it simple_smile

roelof14:12:00

@agile_geek: thanks and yes it's up to me to prove this is working well

agile_geek14:12:33

P.S. Think about what happens to acc on your line (assoc acc (first l1) (first l2))

roelof14:12:33

When it does I hope I will see if I can this with working with just map or reduce

agile_geek14:12:29

Clue: Immutability is a wonderful thing but you have to reason about it carefully when you are used to mutations.

agile_geek14:12:09

Clue2: How does the loop stop?

roelof14:12:14

oke, What I have in mind it that the first item of l1 and the first item of l2 are added to acc

agile_geek14:12:48

Which they are, but what is returned is a new map. acc is unchanged

roelof14:12:22

chips I have to rethink the code one more time

roelof14:12:51

maybe put the whole assoc code into the recur ?

agile_geek14:12:24

Immutability a powerful weapon but wield it with care Padawan!

roelof14:12:08

Sometimes immutablity is driven me grazy

rcanepa14:12:15

Hey @kimsnj, a couple of days ago I bought the ListCast videos about Web Development. It helped me to understand the relation between ring (adapters, middleware, handler) and compojure (routing). From a novice's viewpoint, they worth the money. I wasn't interested in the frontend part, however, I can say that OM is not part of it. The HTML is created using the hiccups library. Anyway, I would totally recommend it to anyone who wants to learn about webdev with Clojure.

agile_geek14:12:22

Sounds like a good idea, but think about the base case for the loop. When will recursion stop.

roelof14:12:42

when l1 or l2 is empty the loop schould stop

agile_geek15:12:09

@roelof: so you need a condition to make that happen. I have to get back to work but will check in with you in 30 mins!

roelof15:12:49

oke, I have changed my code

roelof15:12:33

@agile_geek: this code gives all the right answers :

kimsnj15:12:40

Cool, thanks for the feedback @rcanepa (OM is actually another series of LispCast)

roelof15:12:44

(defn my-zipmap
  [list1 list2]
  (loop
    [acc {}
     l1 list1
     l2 list2]
    (if (or (empty? l1) (empty? l2))
      acc
     (recur (assoc acc (first l1) (first l2)) (rest l1) (rest l2) )))) 

roelof15:12:18

Can I rewrite this so map or recur is used instead of a loop

roelof15:12:41

I doubt about the arguments of the anymous function then

agile_geek15:12:54

You could use map (actually you could do it with reduce too.)

roelof15:12:04

oke, what are then the arguments of the anymous function or do I not have to use one ?

codonnell15:12:14

If you are using reduce, the anonymous function takes two arguments. The first is what will eventually be returned when you are done, and the second is an element from your collection that is being reduced.

roelof15:12:35

corrrect but there are two current items . The first item of list1 and the first item of list2 . Together with a acc there are 3 arguments and im only allow to use 2

codonnell15:12:39

Then you should look for a way to combine your two lists into one argument.

roelof15:12:25

@codonnell: then It will be a list of list [ l1 l2] then the assoc will be more complex then

codonnell15:12:39

If your lists looks like [a1 a2 a3 ...] and [b1 b2 b3 ...], try combining them so they look like [[a1 b1] [a2 b2] [a3 b3] ...]

roelof15:12:53

@codonovan: that is the whole purpose of the 4clojure challenge. Combine them

codonnell15:12:12

I am suggesting you first combine your two lists as above, and then use reduce to convert your new combined list into a map.

roelof15:12:29

@codonnell: thanks, looks like very complicated code . I think I settle for the one with the loop

snowell16:12:10

@roelof: Not sure if you’re still working on that, but you may want to look at interleave

snowell16:12:00

What you’d do with that I’m not sure, but it could be used to shorten your code up!

roelof16:12:42

@snowell: oke, I could use that instead of the long assoc line . I looks I do not have to use map or reduce for it

roelof16:12:28

@snowell: how can I use the clojurebot ?

snowell16:12:55

@roelof: /clj (some line)

roelof16:12:01

aha, I have to convert the answer back to a map

roelof16:12:27

bummer, not working 😞

snowell16:12:44

It’s generally better to do that in a lein repl session

snowell16:12:56

A) It’s quicker B) Less clogging up here 😉

roelof16:12:13

I know. just was thinking aloud

roelof16:12:40

@snowell: can you tell me what is wrong on the into part

snowell16:12:18

Not currently. I can tell you it doesn’t work because it’s expecting a collection of [key value] pairs

roelof16:12:49

oke, I have found another solution . Using hash-map

snowell16:12:51

So (into {} [[:a 1] [:b 2]]) would work

roelof16:12:59

@snowell: this is working (apply hash-map (interleave list1 list2) ) but then I see this {:c 3, :stuck_out_tongue: 2, :a 1} instead of {:a 1, :b 2, :c 3}

snowell16:12:08

That’s totally fine. Order is completely unimportant in maps

roelof16:12:19

oke, then now the next challenge : find the greatest common divider. Something for or this evening or for tomorrow

roelof16:12:26

now time to make dinner

roelof16:12:40

@snowell: thanks for the help

snowell16:12:42

I wish it was that time. I can’t even have lunch yet 😞

snowell16:12:47

No problem!

roelof16:12:57

here it is 17:20 now

roelof16:12:24

American timezone ???

snowell16:12:31

‘Murrica

roelof16:12:41

I live in the Netherlands, so european time

roelof16:12:07

For the GCD I think I can use reduce

codonnell16:12:58

@roelof: The solution I was thinking of using reduce is (reduce conj {} (map vector [:a :b] [1 2]))

codonnell16:12:25

which is essentially the same as (into {} (map vector [:a :b] [1 2])), as @snowell suggested

roelof16:12:34

Thanks, I found a simpler solution : (apply hash-map (interleave list1 list2)

codonnell16:12:29

Also a good solution. An interesting note is that the actual source of zipmap is more similar to your original solution using loop and recur, perhaps because of efficiency concerns.

roelof16:12:13

@codonnell: I have no clue, just learning clojure as a beginner

codonnell16:12:15

@roelof: Your solution is great. You should be proud of it. simple_smile

roelof16:12:23

with a little help sometimes and some tips from the community newcomers can make progress very quick

eggsyntax20:12:18

Anyone know how they added the slackbot /clj functionality? I'd love to add that to one of my other teams...

surreal.analysis20:12:18

@eggsyntax: I believe it's this project - https://github.com/verma/clj-slackbot

eggsyntax20:12:26

Awesome, thanks simple_smile

liss21:12:43

Oof. What's up with this? My vim has gotten really slow, and now I'm getting this error whenever I load a file:

CompilerException java.lang.RuntimeException: No such var: vim-clojure-highlight/ns-syntax-command, compiling:(/priva
te/var/folders/g1/9c8fq9kj61z2nx_ly2k2vwfm0000gn/T/form-init9217007277158111114.clj:1:337)

liss21:12:18

I'm also running into classpath issues. I thought I understood this, but it seems I don't.

liss21:12:09

Mmm, no, I'm not using that one

liss21:12:43

Or do you mean as a solution for my slowness?

codonnell21:12:51

@liss: Have you tried removing vim-clojure-highlight and making sure that's causing the problem?

liss21:12:35

trying that now.

liss22:12:12

It doesn't throw that error when it's off

codonnell22:12:19

@liss: Try installing the most up-to-date version?

liss22:12:53

still there. 😕

liss22:12:03

I haven't had this on for too long

codonnell22:12:01

You have vim-clojure-static and fireplace.vim installed?

codonnell22:12:50

If they are up to date as well, I'm not sure what to tell you. You could try filing an issue on the project's github page.

liss22:12:32

I just checked, and it's just this project that's in bad shape

liss22:12:44

is that expected?

codonnell22:12:23

You mean the plugin works when you open files from other projects in vim?

codonnell22:12:21

Perhaps there is some syntax error in the project that it's choking on, then. You could try debugging the offending project with the plugin disabled.

liss22:12:13

That's my suspicion. I still haven't gotten the hold of Clojure debugging.