This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-07
Channels
- # admin-announcements (54)
- # announcements (1)
- # beginners (145)
- # boot (122)
- # cider (10)
- # cljs-dev (25)
- # cljsrn (20)
- # clojure (173)
- # clojure-art (4)
- # clojure-austria (1)
- # clojure-berlin (3)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-russia (117)
- # clojure-switzerland (1)
- # clojure-uk (3)
- # clojurebridge (6)
- # clojurecup (36)
- # clojurescript (218)
- # clojurex (1)
- # core-typed (17)
- # cursive (23)
- # data-science (1)
- # datavis (2)
- # datomic (28)
- # emacs (3)
- # flambo (1)
- # hoplon (28)
- # ldnclj (19)
- # lein-figwheel (2)
- # leiningen (1)
- # luminus (1)
- # off-topic (1)
- # om (158)
- # portland-or (1)
- # re-frame (72)
- # reagent (48)
- # remote-jobs (1)
- # slack-help (7)
@kyle_schmidt: you should use some kind of io
methods on the :tempfile
it depends on what kind of processing you want to do
@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!
use :content-type
to tell you whether the file is csv
or not
compare MIME type basically
Awesome! :)
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)
incidentally, there is a thing as clojure-csv
Though it's probably not applicable in this case due you are file uploading already
So, you might just want to stick with reader
from
or something
(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)
@trancehime: Thank you so much! You've been a tremendous help!
np, I am also a beginner, so it is good if we can help each other
Anyone alive?
😄 hi
It's 1412 here
So... I'm not European
Whoops :v
OK, I guess better response is I am not living in Europe
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
maybe it's because I haven't wrapped a 'form' object around it
yeah, weird... data is initialized as an int
but when i modify it the value in the atom becomes a String
oh well, I just parse the input to an int
it's fine
Yeah it's pretty weird.
one for myself now : I have this code ; https://www.refheap.com/112449
but now I see this error message : Don't know how to create ISeq from: clojure.lang.Keyword
@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.
@agile_geek: how can I do this more the clojure way then ?
@roelof: firstly you usually associate a key value pair into a map (as it's an associative data structure) using assoc map key value
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)
ok so use different names as I've shown. Obviously add your acc {}
into the loop binding too.
I suspect Clojure is dealing with this OK but it's confusing to humans.
@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.
it is - I'm confusing you. In my code snippet I left it out by accident. Should read loop [l1 list1 l2 list2 acc {} ] ..
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))
)
FYI - you can conj
a key value pair into a map but it's more idiomatic to use assoc
.
@roelof: it will run. Up to you to prove it does what you need. Try it
@agile_geek: thanks and yes it's up to me to prove this is working well
P.S. Think about what happens to acc
on your line (assoc acc (first l1) (first l2))
Clue: Immutability is a wonderful thing but you have to reason about it carefully when you are used to mutations.
Clue2: How does the loop
stop?
oke, What I have in mind it that the first item of l1 and the first item of l2 are added to acc
Which they are, but what is returned is a new map. acc
is unchanged
Immutability a powerful weapon but wield it with care Padawan!
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.
Sounds like a good idea, but think about the base case for the loop. When will recursion stop.
@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!
@agile_geek: this code gives all the right answers :
(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) ))))
You could use map
(actually you could do it with reduce
too.)
oke, what are then the arguments of the anymous function or do I not have to use one ?
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.
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
Then you should look for a way to combine your two lists into one argument.
@codonnell: then It will be a list of list [ l1 l2] then the assoc will be more complex then
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] ...]
@codonovan: that is the whole purpose of the 4clojure challenge. Combine them
I am suggesting you first combine your two lists as above, and then use reduce
to convert your new combined list into a map.
@codonnell: thanks, looks like very complicated code . I think I settle for the one with the loop
@roelof: Not sure if you’re still working on that, but you may want to look at interleave
What you’d do with that I’m not sure, but it could be used to shorten your code up!
@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
Not currently. I can tell you it doesn’t work because it’s expecting a collection of [key value] pairs
@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}
oke, then now the next challenge : find the greatest common divider. Something for or this evening or for tomorrow
@roelof: The solution I was thinking of using reduce
is (reduce conj {} (map vector [:a :b] [1 2]))
which is essentially the same as (into {} (map vector [:a :b] [1 2]))
, as @snowell suggested
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.
@codonnell: I have no clue, just learning clojure as a beginner
@roelof: Your solution is great. You should be proud of it.
with a little help sometimes and some tips from the community newcomers can make progress very quick
Anyone know how they added the slackbot /clj functionality? I'd love to add that to one of my other teams...
@eggsyntax: I believe it's this project - https://github.com/verma/clj-slackbot
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)
I'm also running into classpath issues. I thought I understood this, but it seems I don't.
@liss could it be related to https://github.com/tpope/vim-classpath#faq ?
@liss: Have you tried removing vim-clojure-highlight and making sure that's causing the problem?
@liss: Try installing the most up-to-date version?
You have vim-clojure-static
and fireplace.vim
installed?
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.
You mean the plugin works when you open files from other projects in vim?
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.