Clojurians
#beginners
<
2015-11-18
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

akiva00:11:21

Open-source software.

jethroksy01:11:52

@roelof have you taken a look at squiggly-clojure, if you're using emacs?

jethroksy02:11:29

@liss I find the same issue myself, but I think cryogen is decently small enough for beginners to digest. It's a blogging platform.

danielcompton03:11:59

@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

liss03:11:47

danielcompton: ooh, I love clearly labeled beginner tickets!

roelof17:11:39

Can someone help me. I have this code : http://lpaste.net/145515

roelof17:11:29

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

roelof17:11:09

I think it can be done with apply , conj and repeately but I have no clue where and what I have to change

roelof17:11:28

Someone who is willing to give me some tips

meikemertsch17:11:37

@roelof I have a bit of time, but I am unsure what you want to acheve

roelof17:11:24

@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.

roelof17:11:35

is a exercise of the new brave book

meikemertsch17:11:38

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?

roelof17:11:49

sorry what do you mean with less to pairs, triples and such ?

meikemertsch17:11:44

simple_smile 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?

meikemertsch17:11:37

As with our two sided symmetry there will probably be body parts that exist only once.

meikemertsch17:11:50

Did I understand it correctly?

roelof17:11:53

yes, I think we mean the same. Sorry for the ling time to answer. My daugther needed attention

meikemertsch17:11:53

I took the time to look that whole thing up.

meikemertsch17:11:22

My guess is that for the first of these two exercises you only need something stupid that adds four body parts when given one

roelof17:11:50

Can be, I have no clue

meikemertsch17:11:05

I have an idea. Are you up for instead having the solution presented that I walk you slowly through by questions?

roelof17:11:37

I like that one. If you present it, I learn nothing

meikemertsch17:11:12

great. Ok, let’s see first if you have enough of an understanding of what the functions that you showed me do

roelof17:11:13

can be that it takes a long time , because IM "baby"-sitting y daugther of 10

meikemertsch17:11:37

no worries. I am in no hurry for the next hour

meikemertsch18:11:17

you showed me two functions. look at the symmetrize-function.

roelof18:11:30

oke, in about a hour she must go to bed

meikemertsch18:11:33

Where is the actual action happening?

meikemertsch18:11:54

Meaning where does actually something happen to the parts?

meikemertsch18:11:25

You can go by line numbers in your snippet (if you want to)

meikemertsch18:11:05

very good. What do 35 and 36 actually do?

meikemertsch18:11:16

start maybe with 36

roelof18:11:21

in line 36 a matching part is added to the set which contains all matching parts

roelof18:11:55

in line 35 a loop back is made with the parts which are not matched

meikemertsch18:11:53

Two questions to your answers: what do you mean with “all matching parts” in your answer to 36?

meikemertsch18:11:12

And what do you mean with ‘loop back’ in your answer to 35?

roelof18:11:59

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

roelof18:11:15

So the set has a elements the right and left -eye

roelof18:11:51

with loop back I mean that the code will return back to line 29 the loop function

meikemertsch18:11:56

yes. So all matches for one type of body parts, not all of them over the whole body

roelof18:11:30

sorry for the bad English. It not my mother language which is Dutch

meikemertsch18:11:38

Well, the loop doesn’t happen in line 35. Have a look at that one again. What does line 35 do.. Any clue?

meikemertsch18:11:59

No worries, neither is it mine. I just try to find out what you mean without knowing you well enough 😉

roelof18:11:05

sorry, I look in the wrong line

meikemertsch18:11:32

You don’t have to be sorry. I just want you to take a close look and come up with the solution yourself

meikemertsch18:11:43

It’ll be fine 😉

roelof18:11:11

line 35 the set is added to the final-body parts variable

meikemertsch18:11:48

What do you get as final-body parts before it loops back the first time?

roelof18:11:55

a empty list , see line 30

meikemertsch18:11:58

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…

meikemertsch18:11:16

(you see, I have also trouble expressing exactly what I mean 😉 )

meikemertsch18:11:56

(into final-body-parts
                     (set [part (matching-part part)]))
What is the result of this in the first loop?

roelof18:11:20

[{:name "head" :size 3}]

meikemertsch18:11:41

Aha, I see… nope, that is not how into works simple_smile

meikemertsch18:11:04

you took the head

roelof18:11:04

there will be one head because head contains no left

meikemertsch18:11:26

Just imagine the left-arm is first.

meikemertsch18:11:35

What would it be then?

meikemertsch18:11:43

(just make up a size)

roelof18:11:17

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}

meikemertsch18:11:27

any one of them

roelof18:11:03

it would be [ {:name "left-upper-arm" :size 3}, {:name "right-upper-arm" :size 3}]

meikemertsch18:11:54

So, now to that new problem. You want five different ones now, right?

meikemertsch18:11:26

How did you get two parts out of one in the old code?

roelof18:11:19

because of line 35 / 35 where the parts are added to the final body parts

meikemertsch18:11:33

Ok good. How exactly?

roelof18:11:59

the other part is found by the matching part function 21 - 24

meikemertsch18:11:18

can you do it the same way with five in total instead of two?

roelof18:11:46

I think I have to change line 23 to use a repleatly 4

meikemertsch18:11:07

what would you get then for our arm example?

roelof18:11:43

if you get one arm the same , if you have 2 arms repeatly 3

meikemertsch18:11:59

never mind any other counts right now

meikemertsch18:11:12

just stay with 2 in the old example and 5 in the exercise

roelof18:11:19

Am I on the right track ?

meikemertsch18:11:42

I think you’ll have a problem and will identify it in no time 😉

meikemertsch18:11:58

But you’re sort of on the right track anyway

meikemertsch18:11:46

Ok, let’s have a look at your line 23. What does it do?

roelof18:11:58

it changes the left part in right -part

meikemertsch18:11:14

right. How does repeatedly doing that help you?

roelof18:11:14

I thougt if i can do that multiple times I had the 5 parts

meikemertsch18:11:50

Accordig to you, that line changes the left part into the right part, right?

meikemertsch18:11:19

If you do that 5 times, what do you get?

roelof18:11:59

second thought I had is change 36 to add the repeatly between the set and the part

meikemertsch18:11:21

Aha simple_smile you’re very much closer now

meikemertsch18:11:39

but not completely there yet

meikemertsch18:11:57

what would you get when repeatedly doing that.

meikemertsch18:11:03

no worries, you’re very close

meikemertsch18:11:24

I can add that you might have to think a bit easier

roelof18:11:37

you are right I do get 5 times both parts

meikemertsch18:11:51

that’s not what you want, right?

meikemertsch18:11:06

small tip: you want more than one change 😉

meikemertsch18:11:21

in line 36 you’re pretty right

meikemertsch18:11:41

again: how did you get a second part to your original?

roelof18:11:06

then I think between matching part and part

meikemertsch18:11:25

another tip: drop the repeatedly for now

roelof18:11:41

because of this part in line 36 (matching-part part)

meikemertsch18:11:41

It looks exactly like what you want but you might not need it yet

meikemertsch18:11:49

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?

roelof18:11:34

(clojure.string/replace (:name part) #"^left-" "center-")

meikemertsch18:11:51

That would be how a center function is implemented

meikemertsch18:11:11

Just imagine it existed. You don’t have to write it. But use the center-part

roelof18:11:19

oke, then you could multiple time the replace and change the left in something like arm-1 , arm2 and so on

meikemertsch18:11:22

You have an idea how to get other parts.

meikemertsch18:11:36

But do you know how to get them into your final-body-parts?

roelof19:11:03

still thinking now

meikemertsch19:11:10

Do you need help?

meikemertsch19:11:24

In which lines are you trying to squeeze it in?

roelof19:11:30

Im thinking about line 23 and line 36 but line 23 seems to return one string and not multiple strings

meikemertsch19:11:00

well, actually it does not return a string but a map.

meikemertsch19:11:06

But it’s a single part

roelof19:11:30

oke, I could use conj to add more items to a map

meikemertsch19:11:44

so how did the matching-part end up in the final-body-parts?

meikemertsch19:11:21

Did you need a conj?

roelof19:11:35

no, there a into is used

meikemertsch19:11:03

Would you like to use that again?

roelof19:11:30

so I could use a into to make all the parts into line 23

meikemertsch19:11:51

but matching-part returns only one part, right?

meikemertsch19:11:20

More specific it even returns only right parts

roelof19:11:40

bummer, back to the drawing table

meikemertsch19:11:48

nono…. you’re close

meikemertsch19:11:57

you have just overlooked something I assume

roelof19:11:06

I think i have all the pieces of the puzzle but i cannot make the whole puzzle

meikemertsch19:11:10

what does the very first function in line 36 do?

roelof19:11:24

maybe overthinking , that happens more to me

meikemertsch19:11:36

Japp, I know that feeling 😕

roelof19:11:42

it makes a set

meikemertsch19:11:52

a set of what?

roelof19:11:13

a set of a part and the matching part

meikemertsch19:11:28

what if you had a center-part?

meikemertsch19:11:34

could you smuggle it in?

roelof19:11:53

(set ( [part (matching-part part)] [part (center-part part)])

meikemertsch19:11:07

think a bit easier, please

meikemertsch19:11:33

actually… maybe it’s just reading the brackets closer

meikemertsch19:11:02

your code would throw an error

meikemertsch19:11:37

when you use the normal round brackets, the first element is expected to be a function.

meikemertsch19:11:06

Your closing brackets are much better, by the way 😉

meikemertsch19:11:13

(I guess that you’re unfamiliar with the set function)

roelof19:11:15

(set ( [part (matching-part part)])) (set ( [part (center-part part)]))

meikemertsch19:11:44

Ok, let’s just pause this for a second and unpack our drawing board.

meikemertsch19:11:51

how does set work?

roelof19:11:19

it takes a list and returns a set where all items must be unique

roelof19:11:47

(set ( 1,2,1] ) gives (1,2)

roelof19:11:29

nope , also strings and keywords

meikemertsch19:11:30

Can I do (set [1 2])?

meikemertsch19:11:38

That’s a vector

meikemertsch19:11:04

good. what does (set [a b])give?

roelof19:11:21

oke, then I give it a false name. I named [ ] a list

meikemertsch19:11:43

#{a b} is how a set looks like simple_smile

meikemertsch19:11:55

but I guess that’s what you meant.

meikemertsch19:11:18

OK, so what does (set [part (matching-part part)]) give?

roelof19:11:35

I think I have to reread the chapter and make a little paper where I can cheat

meikemertsch19:11:53

just one step after the other simple_smile

meikemertsch19:11:00

you’re really close now

roelof19:11:27

a example ( { left-arm} , { right-arm} )

meikemertsch19:11:08

just the list is not a list but a set #{{ left-arm} , { right-arm} }

roelof19:11:30

time to go to bed

meikemertsch19:11:41

good point, @swizzardhttp://conj.io is the short form for it 😉

meikemertsch19:11:04

can you take one more thing @roelof ?

meikemertsch19:11:28

what would give you (set [a b c])?

meikemertsch19:11:53

no conj needed

roelof19:11:55

they all are unique items

meikemertsch19:11:17

when you return to our limbs, you can smuggle the center-part in

roelof19:11:36

oke, a b and c could be function calls ?

meikemertsch19:11:19

a b c are evaluated things. They could be for example (matching-part part) and (center-part part)

roelof19:11:24

(set [part (matching-part part) (center-part part) ])))))))

swizzard19:11:38

by george he’s got it!

roelof19:11:06

so I have to make multiple functions which looks like matching part

roelof19:11:21

and then call them in line 36

meikemertsch19:11:26

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 😉

meikemertsch19:11:37

then you don’t need more functions

meikemertsch19:11:43

because they’ll all look the same

meikemertsch19:11:57

I guess you’ll get that one

meikemertsch19:11:08

otherwise I’ll happily help you

roelof19:11:30

oke, then I have to read how the replace part works first

meikemertsch19:11:38

But the tip with http://conj.io helped me save my… well, a lot of times 😉

roelof19:11:15

hmm, replace cannot have multiple arguments

meikemertsch19:11:26

nope. you have all the arguments you need

meikemertsch19:11:37

but your function matching-part needs another one

meikemertsch19:11:05

then you can replace “left-“ by whatever you want...

roelof19:11:02

yes, I try to figure out what it will be . The page seems not have a example of it

meikemertsch19:11:04

you basically said it yourself already:

meikemertsch19:11:05

(clojure.string/replace (:name part) #"^left-" "center-")

meikemertsch19:11:11

that’s what you wrote

meikemertsch19:11:52

just “center-“ is as fixed as “right-“…

roelof19:11:57

oke then I have three parts . The other parts the name also have to be changed

meikemertsch19:11:41

in line 23. What would happen if you wrote (clojure.string/replace (:name part) #"^left-" replacement)

roelof19:11:23

then all the left are changed in what the contents of the replacement is

meikemertsch19:11:32

is that useful?

roelof19:11:01

Could I do something like this then

roelof19:11:54

(clojure.string/replace (:name part) #"^left-" #{right, center, right2, left2} )

meikemertsch19:11:09

that’ll not work...

meikemertsch19:11:37

you’ll need to change the input for matching-parts

meikemertsch19:11:51

at the moment you just put in a part, right?

meikemertsch19:11:24

can you put in a part and, say, a replacement?

roelof19:11:51

yes, change the arguments and the call function

meikemertsch19:11:10

what would your line 36 look like?

roelof19:11:43

One question : what is the type of the argument

meikemertsch19:11:52

Clojure is typeless.

roelof19:11:16

wait , I see it

meikemertsch19:11:26

As far as I understand (careful: thin ice) it’s evaluated at runtime

meikemertsch19:11:50

Ok, I wait 😄

roelof19:11:13

(set [part (matching-part part right ) (center-part part center ) ])))))))

meikemertsch19:11:23

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

meikemertsch19:11:50

otherwise rightand center will be interpreted as symbols that you didn’t define

meikemertsch19:11:04

but your solution’s core is correct

meikemertsch19:11:32

(set [part (matching-part part “right-" ) (matching-part part “center-" ) ])

roelof19:11:24

oke, very difficult exercise for a first chapter

meikemertsch19:11:25

now matching-part needs some love. I guess you can write it now?

meikemertsch19:11:18

I guess it’s quite a ride. Maybe it’s easier for you if you did the clojurescriptkoans as well?

meikemertsch19:11:39

(I know it’s Clojure Script, but it doesn’t make much difference… )

meikemertsch19:11:53

That’s how I started and that gave me a much easier start.

meikemertsch19:11:10

then much of the brave book starts off easier

roelof19:11:21

(defn matching-part [part replacement ] (clojure.string/replace (:name part) #"^left-" replacement) :size (:size part)})

roelof19:11:46

I hope now I get a 6 out of 10

meikemertsch19:11:46

now you just need to invent two more parts 😉

roelof19:11:08

which parts ??

meikemertsch19:11:33

well, so far you have three (left right and center) but your creature needs five, right?

roelof19:11:46

right, that is no problem anymore

roelof19:11:52

I see how it works,

roelof19:11:57

Thanks for the patience and time

meikemertsch19:11:03

you got the principle now

meikemertsch19:11:13

Seems like you did a good job 😄

meikemertsch19:11:29

If you want to try those koans out: http://clojurescriptkoans.com/

meikemertsch19:11:12

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

roelof19:11:40

oke, again thanks for the time and patience

meikemertsch19:11:05

Absolutely. I was lucky to have an as patient teacher. And I started with Clojure only this year

roelof19:11:38

oke, you are also a patient teacher

meikemertsch19:11:23

Think about the next exercise as well… it’s not that hard anymore but you’ll still need to think a bit

meikemertsch19:11:43

I’m off for today. Need to walk my dog now simple_smile

meikemertsch20:11:57

@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

swizzard20:11:12

i like it being in beginners

swizzard20:11:29

although that’s undoubtedly a function of it having been fairly quiet in here

meikemertsch20:11:47

That was my thought, too. In other channels I'd like it less

swizzard20:11:14

i think on other media/forums it would’ve been worse too

swizzard20:11:38

i’m sure you’re familiar with the common irc situation of randos popping in to ask bewildering questions

meikemertsch20:11:04

I'm not sure what you mean

meikemertsch20:11:28

That happens more in 'general' I guess

swizzard20:11:42

i guess it also helps that this is for a language as opposed to a library

swizzard20:11:11

i’ve seen irc channels for libraries that are just a bunch of people asking their own questions

swizzard20:11:42

and it’s just a raft of nonsense until the mods/maintainers find the time to address it

meikemertsch20:11:53

Thanks for the feedback

meikemertsch20:11:55

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

swizzard20:11:30

you did great!

swizzard20:11:38

it was honestly kind of a great thing to witness

meikemertsch20:11:51

Oh, my... I'm beed red now. But I think I'd do it again

liss21:11:52

What's the current recommended Clojure beginner book?

seancorfield21:11:20

Clojure for the Brave and True gets a lot of props from folks.

liss22:11:58

Okay, that's been my go to. Wasn't sure if there was a new one.

surreal.analysis23:11:10

@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