This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-09
Channels
- # beginners (140)
- # boot (163)
- # cider (43)
- # cljs-dev (50)
- # cljsjs (5)
- # cljsrn (38)
- # clojure (152)
- # clojure-austria (10)
- # clojure-berlin (9)
- # clojure-dev (11)
- # clojure-japan (1)
- # clojure-miami (2)
- # clojure-russia (147)
- # clojure-sg (12)
- # clojurescript (244)
- # code-reviews (3)
- # cursive (104)
- # data-science (5)
- # datavis (15)
- # datomic (35)
- # editors (4)
- # hoplon (1)
- # ldnclj (11)
- # lein-figwheel (14)
- # leiningen (22)
- # off-topic (53)
- # om (373)
- # omnext (2)
- # onyx (67)
- # parinfer (193)
- # re-frame (23)
- # reagent (89)
- # yada (7)
Anyone have experience sending a file to download in compojure?
Is it possible for a user to submit a file via POST, the server does stuff to the file, then returns the changed file all in one swoop?
I've done image upload via compojure before, but I haven't had much experience with returning the changed file in the same operation
Though I suggest taking a look at output-stream
to do the returning part
Good morning. I try to solve the last exercise of the do-things of the brave book : http://www.braveclojure.com/do-things/ . To solve this one. Do I need to change the symmetrize-body-parts or the matching-part function ?
Second question : Why do I see this error : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long, compiling:(C:/Users/rwobb/IdeaProjects/clojure-exercises/src/clojure_exercises/core.clj:12:1) on this code :
(defn my_intersection
[set1 set2]
(reduce (fn[acc item] (if (contains? set2 item) (conj acc item) acc)) {} set1 )
)
(my_intersection #{0 1 2 3} #{2 3 4 5})
Not sure, but don't you want to return a set, so the 'seed' for your reduce should be #{} rather than {}.
Yeah I just tested and that fixes it. Apart from that small error I think you nailed it! Gives the answer #{3 2}
So, when I use partition
without supplying step
I should get a sequences of lists containing n
items each as I specified in n
... If I want to check if the count
of each list in that sequence is equal to a number, should I use map
or apply
That sounds right to me. Your last one may have less in it or some may be left off I can't remember, I always look up https://clojuredocs.org/clojure.core/partition, then check its variants, to get what I want.
Well, partition
when not supplying a step
will drop the last set if it does not form a full partition
anyone who wants to help me to solve the last exercise of the do-things of the brave book
it's this challenge : https://www.refheap.com/112511
pity. I wonder to solve this I have to change the symmetrize function or also the parts function
I need all my brain space right now for 96 on 4clojure. The last few easy ones are pretty hard. Maybe I'll still be at it by the time you catch up to me, and then you can give me a hand...
You can tell they are not that easy when not so many people have completed them, yet they have a low number.
You got that reduce pretty well, and reduce is pretty difficult when you first see it.
@cjmurphy: which one is 96?
For this one (http://www.4clojure.com/problem/62) Can I use loop - recur. Then if so, then I have to think how to stop the loop
try it but if Im wrong I have a function which works till infinity and a computer which will be slower and slower 😞
more knowledgeable about the web, I think he means
I get the feeling that the remark of @cjmurphy was not intented to answer my question ?
For this one (http://www.4clojure.com/problem/62) Can I use loop - recur. Then if so, then I have to think how to stop the loop
Which you do by wrapping it with lazy-seq, which means nothing will happen unless you force it out, with something like a take
.
Conceptually very interesting the whole laziness thing. Not exactly easy to think about, but possible to get results with regardless.
I actually think that here is the best place for questions about 'exercises in the Brave book'. If people want to help they join this beginners channel.
lazy~
Laziness in Clojure is a pain point, IMO. 99% of the time everything just works and you don't even notice what parts are lazy and what parts aren't, and then every once in a while you get an error because of it, and those errors seem cryptic for quite a while after you start working w/ Clojure.
In some ways it'd be easier if the language were either consistently eager or consistently lazy. It's one of the few complaints I have about the language.
Sorry, I shall slep
good night then , @trancehime
Why do I get this error message : ArityException Wrong number of args (0) passed to: core/eval1476/fn--1477 clojure.lang.AFn.throwArity (AFn.java:429) on this code :
(defn roelof
[function number]
(lazy-seq (cons number(function) )
))
(take 5 (roelof #(* 2 %) 1))
You need a space between number
and (function)
would be my guess
Nope, that's not it. I never realized that didn't matter in Clojure at all
The issue is that you're calling function
With no arguments
But the function you passed in #(* 2 %)
Takes an argument (represented by %
)
oke, the argument is number if I understand everything well ? @surreal.analysis
I think so, but I'm not positive what you're trying to do. What do you expect the result of the last statement to be?
Because cons also takes 2 arguments, but if you move number it will only take 1. It also needs a base collection
I try to solve this challenge : http://www.4clojure.com/problem/62
As it takes an element and a collection
@surreal.analysis: then I have to think good what the collection is
I think the issue is you likely want some recursion
Right, but you want to call the roelof
function from inside roelof
@surreal.analysis: so more a function like this :
(defn sum-last-2
([] (sum-last-2 1 2))
([n m] (cons n (lazy-seq (sum-last-2 m (+ n m))))))
Yes, pretty similar, but you shouldn't need the 0 arguments option, and you need to replace the m (+ n m)
part with your code
hmm, still a problem : I have now this (cons number (lazy-seq (my-iterate number (function number)))
but see this error message : ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn
and when I do (cons number (lazy-seq (my-iterate function number))))
the function does not get executed I see as output { 1 1 1 1 1 }
now hope someone can help me with my brave problem and I solved the number of exercises I want on a day
exercise 6 of the do-things chapter. See here :
6.Create a function that generalizes symmetrize-body-parts and the function you created in Exercise 5. The new function should take a collection of body parts and the number of matching body parts to add
the functions can be found here : https://www.refheap.com/112518
let me open http://www.braveclojure.com/do-things/ 😛
I changed this
(set [part (matching-part part))
to this (set [part (matching-part part "right1-")
(matching-part part "right2-")
(matching-part part "right3-")
(matching-part part "right4-")
(matching-part part "right5-")
and
{:name (clojure.string/replace (:name part) #"^left-" "right-")
to this {:name (clojure.string/replace (:name part) #"^left-" replacement)
This is not working
(into final-body-parts (set [part ( repeatedly (matching-part part "right1-") number)
])))
Then I see this error message : clojure.lang.PersistentArrayMap cannot be cast to java.lang.Number
no, im trying to solve a exercise of the brave book where I ,must generalize a function so it works on a given number and not on a fixed number
I have to generilaze this function : https://www.refheap.com/112520
Here is one hint: (map #(str %1 "-") (range 1 n)) to change up how you have the symmetric thing in there.
Something like that: https://www.refheap.com/112523
@base698: it this part right ;
(defn symmetrize-body-parts
"Expects a seq of maps that have a :name and :size"
([asym-body-parts] (symmetrize-body-parts asym-body-parts 2))
([asym-body-parts n]
so it can take the optional number. You can call it like (symmetrize-body-parts parts-list) or (symmetrize-body-parts parts-list 5)
yeah, that's the default case when you call it like that it does 2 (mimicing left/right)
oke, it works also without the optional number and then it looks like this : https://www.refheap.com/112526
but now the output looks like this :
{:name "left-eye", :size 1}
{:name "2-eye", :size 1}
{:name "1-eye", :size 1}
What do I have to change to make it work like this :
{:name "eye1", :size 1}
{:name "eye2", :size 1}
{:name "eye3", :size 1}