This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-10
Channels
- # aws (45)
- # bangalore-clj (16)
- # beginners (109)
- # boot (137)
- # cider (7)
- # cljs-dev (54)
- # cljsrn (22)
- # clojure (77)
- # clojure-conj (1)
- # clojure-greece (2)
- # clojure-nl (5)
- # clojure-russia (36)
- # clojure-spec (15)
- # clojure-uk (54)
- # clojurescript (118)
- # cursive (7)
- # datomic (25)
- # emacs (33)
- # hoplon (276)
- # klipse (38)
- # lein-figwheel (1)
- # leiningen (9)
- # melbourne (1)
- # off-topic (18)
- # om (98)
- # onyx (6)
- # pedestal (1)
- # perun (24)
- # re-frame (46)
- # reagent (6)
- # ring-swagger (3)
- # spacemacs (67)
- # specter (15)
- # untangled (33)
- # vim (6)
beginner q about partition
: why does (partition 10 ‘(1 2 3))
return an empty list?
I'd think from the docs it would return either ((1 2 3))
or (1 2 3)
. am I totally off there?
@mss The reason is that you do not have enough elements to make a single partition of that size. partition-all
works the way you want.
@avabinary Usually you should go ahead and ask away. Don't ask to ask. That being said, I have no clue about Korma
tried using the
(raw ...)
inside (insert users (values {:name "bob" :job "clojurian"} (raw "ON DUPLICATE KEY `name`="bob" UPDATE ...")))
@avabinary check that you are correctly escaping double quotes in your string
(raw "ON DUPLICATE KEY 'name'="bob" UPDATE ...")
should be (raw "ON DUPLICATE KEY 'name'=\"bob\" UPDATE ...")
I think
Someone who can give me some hints on exercise 5 here : http://www.braveclojure.com/do-things/#Exercises
I think I have to rewrite this code :
(defn better-symmetrize-body-parts
"Expects a seq of maps that have a :name and :size"
[asym-body-parts]
(reduce (fn [final-body-parts part]
(into final-body-parts (set [part (matching-part part)])))
[]
asym-body-parts))
@roelofw: the exercise just says to write a similar function that produces 5 of each body part. I'd probably start afresh but use the structure of that function as a guide for my new function.
Then exercise 6 wants you to produce another new function that accepts a number as well as a collection and produces a result with that many of each part.
At least, that's my reading of what you linked to. I haven't read that book nor tried the exercises.
Looking at the code, I'm guessing matching-part
is key?
@seancorfield I think so. this is a part of the output of the orginal function :
[{:name "head", :size 3}
{:name "left-eye", :size 1}
{:name "right-eye", :size 1}
{:name "left-ear", :size 1}
{:name "right-ear", :size 1}
@roelofw I too am not familiar with the exercises or the book however I think matching-part
is currently returning the right-
version of a left handside part e.g. given left-eye
returns right-eye
which better-symmetrize-body-parts
is then adding as a set into the final-body-parts
using reduce to accumulate the final body parts collection. Your going to have to create a fn that given a left body part - returns 5 body parts instead i.e. eye-1
, eye-2
etc. and use that in a new version of better-symmetrize-body-parts
. As with most things there are several ways to do this.
@agile_geek Oke, im thinking of chancing this line (into final-body-parts (set [part (matching-part part)])))
to
(into final-body-parts(iterate 5 (set [part (matching-part part)]))))`
I only have to find out how I make the number a parameter of the other function so I get the output the challenge wanted
@roelof try it but I don't think it will give you what you are expecting.
@agile_geek nope, it gives me this error message :
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn clojure.core/iterate (core.clj:2904)
maybe I better can do chapter 4 and 5 first , Maybe then I get a idea how to solve these 2
@roelofw (iterate f x)
returns a lazy sequence of (x, (f x), (f (f x)), ....)
so you're asking it to call (5 (set [part (matching-part part)]))
and 5
is not a function
Oke, that is not what I wanted. I wanted something like this in a imperatieve language ;
for i = 1 to 5 ; matching-part(i)
i think it might be better to modify matching-part to return what you want, rather than call it for the same result 5 times.
Still think you have a problem - call (matching-part {:name "left-eye" :size 1})
in a repl and see what it returns...then think about calling it many times
exactly what I suggested further up
that one gives this output : (do-things.core/matching-part {:name "left-eye", :size 1})
but when I do it like this :
(def asym-hobbit-body-parts [{:name "left-eye" :size 1}])
(defn matching-part
[part]
{:name (clojure.string/replace (:name part) #"^left-" "right-")
:size (:size part)})
(defn better-symmetrize-body-parts
"Expects a seq of maps that have a :name and :size"
[asym-body-parts]
(reduce (fn [final-body-parts part]
(into final-body-parts (set [part (matching-part part)])))
[]
asym-body-parts))
maybe I can change something in this line : {:name (clojure.string/replace (:name part) #"^left-" "right-")
the prompt specifically says it’s difficult, read ahead and you might learn more and you can revisit it.
keep reading, it’s good stuff. just know that it’s supposed to feel this way, no one gets it immediately.
and used it like this :
(only_names(glitter-filter 3 (mapify (parse (slurp filename)))))
I have this code :
(defn append_name
[name gitter-index records]
(into records {:name name :gitter-index gitter-index}))
and now I see this error message : ClassCastException java.lang.Long cannot be cast to clojure.lang.IPersistentCollection clojure.core/conj--4345 (core.clj:82)
looks like records will be equal to 2 and into's first argument should be a collection
When I do (append_name "Roelof" 2 (mapify (parse (slurp filename))))
I see this output :
[:gitter-index 2]
[:name "Roelof"]
I see then this answer : => (fwpd.core/mapify (fwpd.core/parse (clojure.core/slurp fwpd.core/filename)))
Sorry, I did it again and saw this output :
mapify (parse (slurp filename)))
=>
({:name "Edward Cullen", :glitter-index 10}
{:name "Bella Swan", :glitter-index 0}
{:name "Charlie Swan", :glitter-index 0}
{:name "Jacob Black", :glitter-index 3}
{:name "Carlisle Cullen", :glitter-index 6})