This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-18
Channels
- # admin-announcements (4)
- # beginners (306)
- # boot (191)
- # bristol-clojurians (4)
- # business (3)
- # cbus (4)
- # cider (6)
- # cljsrn (51)
- # clojure (147)
- # clojure-canada (1)
- # clojure-conj (6)
- # clojure-japan (2)
- # clojure-poland (8)
- # clojure-russia (57)
- # clojure-sg (1)
- # clojurecup (1)
- # clojurescript (229)
- # core-async (4)
- # cursive (47)
- # data-science (2)
- # datomic (3)
- # emacs (6)
- # events (1)
- # hoplon (16)
- # immutant (33)
- # jobs (1)
- # ldnclj (7)
- # off-topic (25)
- # om (69)
- # onyx (7)
- # re-frame (35)
- # reagent (3)
- # yada (4)
@liss I find the same issue myself, but I think cryogen is decently small enough for beginners to digest. It's a blogging platform.
@liss there’s a bunch of easy tickets for clj-rethinkdb I’d be happy to have help with https://github.com/apa512/clj-rethinkdb/labels/easy
Can someone help me. I have this code : http://lpaste.net/145515
now I have to make it work so that it can have let's say 5 arms so instead of symetric it will be asymatric
I think it can be done with apply , conj and repeately but I have no clue where and what I have to change
@roelof I have a bit of time, but I am unsure what you want to acheve
@meikemertsch: the exact exercise is this : Create a function that’s similar to symmetrize-body-parts except that it has to work with weird space aliens with radial symmetry. Instead of two eyes, arms, legs, and so on, they have five.
Yeah, I recognize it now. So to radial-symmetrize a body, it’ll add four more to any single limb and less to pairs, triples and such?
if it has a single limb like a leg (let’s call it leg A) the symmetrize function is expected to give it four more legs (maybe B, C, D and E), while if it has already two arms, say for example A and C, the function is supposed to add just three more arms to make it symmetrical (on each of a B, D and E arm). Right so far?
As with our two sided symmetry there will probably be body parts that exist only once.
Did I understand it correctly?
yes, I think we mean the same. Sorry for the ling time to answer. My daugther needed attention
No worries.
I took the time to look that whole thing up.
My guess is that for the first of these two exercises you only need something stupid that adds four body parts when given one
I have an idea. Are you up for instead having the solution presented that I walk you slowly through by questions?
great. Ok, let’s see first if you have enough of an understanding of what the functions that you showed me do
no worries. I am in no hurry for the next hour
you showed me two functions. look at the symmetrize-function.
Where is the actual action happening?
Meaning where does actually something happen to the parts?
You can go by line numbers in your snippet (if you want to)
very good. What do 35 and 36 actually do?
start maybe with 36
Two questions to your answers: what do you mean with “all matching parts” in your answer to 36?
And what do you mean with ‘loop back’ in your answer to 35?
with all matching parts I mean for example in line 2 there is a left-eye , When it symmetric I also need a right-eye
yes. So all matches for one type of body parts, not all of them over the whole body
Well, the loop doesn’t happen in line 35. Have a look at that one again. What does line 35 do.. Any clue?
No worries, neither is it mine. I just try to find out what you mean without knowing you well enough 😉
You don’t have to be sorry. I just want you to take a close look and come up with the solution yourself
It’ll be fine 😉
Ok, great.
What do you get as final-body parts before it loops back the first time?
nope, that is what you start with before you do anything. I mean between it being empty and it actually looping. You can also say what is final-body-parts at the beginning of the next loop…
(you see, I have also trouble expressing exactly what I mean 😉 )
(into final-body-parts
(set [part (matching-part part)]))
What is the result of this in the first loop?Aha, I see… nope, that is not how into works
Oh wait
you took the head
Yes 😄
great
Just imagine the left-arm is first.
What would it be then?
(just make up a size)
you mean a complete arm or just one of these parts : {:name "left-upper-arm" :size 3} / {:name "left-forearm" :size 3} / {:name "left-hand" :size 2}
any one of them
yes. Good.
So, now to that new problem. You want five different ones now, right?
How did you get two parts out of one in the old code?
Ok good. How exactly?
great!
can you do it the same way with five in total instead of two?
what would you get then for our arm example?
never mind any other counts right now
just stay with 2 in the old example and 5 in the exercise
I think you’ll have a problem and will identify it in no time 😉
But you’re sort of on the right track anyway
Ok, let’s have a look at your line 23. What does it do?
right. How does repeatedly doing that help you?
Accordig to you, that line changes the left part into the right part, right?
If you do that 5 times, what do you get?
Aha you’re very much closer now
but not completely there yet
what would you get when repeatedly doing that.
no worries, you’re very close
I can add that you might have to think a bit easier
very good
that’s not what you want, right?
small tip: you want more than one change 😉
in line 36 you’re pretty right
again: how did you get a second part to your original?
another tip: drop the repeatedly for now
It looks exactly like what you want but you might not need it yet
what if you had another function that could make a “center” part out of a left part? How would you use that part in line 36?
That would be how a center function is implemented
Just imagine it existed. You don’t have to write it. But use the center-part
oke, then you could multiple time the replace and change the left in something like arm-1 , arm2 and so on
sort of.
You have an idea how to get other parts.
But do you know how to get them into your final-body-parts?
Do you need help?
In which lines are you trying to squeeze it in?
Im thinking about line 23 and line 36 but line 23 seems to return one string and not multiple strings
right!
well, actually it does not return a string but a map.
But it’s a single part
so how did the matching-part end up in the final-body-parts?
Did you need a conj?
Would you like to use that again?
but matching-part returns only one part, right?
More specific it even returns only right parts
nono…. you’re close
you have just overlooked something I assume
what does the very first function in line 36 do?
I see it 😄
Japp, I know that feeling 😕
a set of what?
great
what if you had a center-part?
could you smuggle it in?
uhm...
think a bit easier, please
actually… maybe it’s just reading the brackets closer
your code would throw an error
when you use the normal round brackets, the first element is expected to be a function.
Your closing brackets are much better, by the way 😉
does http://conj.io/store/v1/org.clojure/clojure/1.7.0/clj/clojure.core/set/ help?
(I guess that you’re unfamiliar with the set function)
Ok, let’s just pause this for a second and unpack our drawing board.
how does set work?
only lists?
Can I do (set [1 2])
?
That’s a vector
good. what does (set [a b])
give?
#{a b} is how a set looks like
but I guess that’s what you meant.
OK, so what does
(set [part (matching-part part)])
give?
haha...
just one step after the other
you’re really close now
@roelof do you have https://jafingerhut.github.io/cheatsheet/grimoire/cheatsheet-tiptip-cdocs-summary.html bookmarked?
just the list is not a list but a set #{{ left-arm} , { right-arm} }
good point, @swizzard … http://conj.io is the short form for it 😉
can you take one more thing @roelof ?
what would give you (set [a b c])
?
great
no conj needed
see it now?
when you return to our limbs, you can smuggle the center-part in
a b c are evaluated things. They could be for example (matching-part part) and (center-part part)
yeay!
great!!
one more thing you want to do is giving the matching-part a possibility to change into more than only “right-“… you want another argument 😉
then you don’t need more functions
because they’ll all look the same
I guess you’ll get that one
otherwise I’ll happily help you
But the tip with http://conj.io helped me save my… well, a lot of times 😉
Sleep well
nope. you have all the arguments you need
but your function matching-part needs another one
then you can replace “left-“ by whatever you want...
makes sense?
you basically said it yourself already:
(clojure.string/replace (:name part) #"^left-" "center-")
that’s what you wrote
just “center-“ is as fixed as “right-“…
right.
in line 23. What would happen if you wrote (clojure.string/replace (:name part) #"^left-" replacement)
is that useful?
that’ll not work...
you’ll need to change the input for matching-parts
at the moment you just put in a part, right?
can you put in a part and, say, a replacement?
what would your line 36 look like?
Clojure is typeless.
As far as I understand (careful: thin ice) it’s evaluated at runtime
Ok, I wait 😄
Ah, I see now the reason for your question. Yes, I’d just adjust the quotations marks for the strings that are needed in the replace function
otherwise right
and center
will be interpreted as symbols that you didn’t define
but your solution’s core is correct
(set [part (matching-part part “right-" ) (matching-part part “center-" ) ])
now matching-part
needs some love. I guess you can write it now?
I guess it’s quite a ride. Maybe it’s easier for you if you did the clojurescriptkoans as well?
(I know it’s Clojure Script, but it doesn’t make much difference… )
That’s how I started and that gave me a much easier start.
then much of the brave book starts off easier
(defn matching-part [part replacement ] (clojure.string/replace (:name part) #"^left-" replacement) :size (:size part)})
Great!
you got it
now you just need to invent two more parts 😉
well, so far you have three (left right and center) but your creature needs five, right?
you got the principle now
Seems like you did a good job 😄
If you want to try those koans out: http://clojurescriptkoans.com/
I had a lot of fun. It might just make your start a lot easier. Having done some of them and taken http://conj.io as cheat sheet, will help you getting into the brave book easier
Absolutely. I was lucky to have an as patient teacher. And I started with Clojure only this year
Thanks...
Think about the next exercise as well… it’s not that hard anymore but you’ll still need to think a bit
I’m off for today. Need to walk my dog now
good luck
@swizzard: I'd like your opinion about something. One one hand I could have taken the whole conversation in a private channel and was all along thinking about it because it might be too detailed. On the other hand you might not have given the cheat sheet tip that did not cross my mind without it. What do you think about it. I can adjust for the future
That was my thought, too. In other channels I'd like it less
😅 yes
i’m sure you’re familiar with the common irc situation of randos popping in to ask bewildering questions
I'm not sure what you mean
That happens more in 'general' I guess
i’ve seen irc channels for libraries that are just a bunch of people asking their own questions
and it’s just a raft of nonsense until the mods/maintainers find the time to address it
Thanks for the feedback
Being so new to Clojure myself I rather didn't want to teach roelof completely on my own. Just in case that there are much smarter solutions
Oh, my... I'm beed red now. But I think I'd do it again
Clojure for the Brave and True gets a lot of props from folks.
@liss: I'm also a big fan of Living Clojure if you're looking for alternatives, but Brave and True is still a great book