Fork me on GitHub
#beginners
<
2016-11-18
>
roelofw08:11:25

A little problem of the clojure koans. The only one that I cannnot solve :

"You can also create a new object from another object with metadata"
  (= {:league "National League" :park "AT&T Park"}
     (meta (vary-meta giants
                      assoc {"test" "National Leaque"}))) 

roelofw08:11:59

now I see this error : 'ArityException Wrong number of args (2) passed to: core/assoc--4371 clojure.lang.AFn.throwArity (AFn.java:429)'

johnny.martin12:11:56

You almost got it. To fix the arity exception, drop the curlies.

... assoc "test" "National Leaque" )))
Then you are almost home.

roelofw13:11:45

you brought me on the right track

roelofw14:11:59

Can this be improved :

(fn [key map]  (if (contains? map key) (nil? (map key)) false)) 

roelofw14:11:17

its my solution to 4clojure challenge 134

agile_geek14:11:38

There are other ways to write it but most of them are not as succinct

verma14:11:29

wouldn't (nil? (get map key ::not-found)) work?

roelofw14:11:14

@agile_geek sorry, my English is not very good, What does succint mean

roelofw14:11:16

@verma : I do not think so, the answer of the challenge need to be true or false

agile_geek14:11:06

@roelofw most of the other versions are more code and/or not as clear

verma14:11:53

@roelofw nil? does return true or false though

roelofw14:11:25

yes, but if they key is not in the map , I think your code returns ::not-found and it suppose to return false

roelofw14:11:51

I love to write clear code

agile_geek14:11:52

@verma (nil? (get map key false)) would probably do the job tho

verma14:11:52

@roelofw ::not-found is then evaluated through nil? which returns false.

agile_geek14:11:20

true... or is that false?

verma14:11:55

@agile_geek sure, that works as well, get returning anything other than nil for no key found is good :thumbsup:

verma14:11:21

::not-found is not nil so (nil? ::not-found) is false

agile_geek14:11:40

You can even drop the get if map is never nil (fn [key map] (nil? (map key :not-found))

verma14:11:48

:thumbsup:

roelofw14:11:11

oke, learned another thing

agile_geek14:11:17

@roelofw a map (the datastructure) is itself a function that takes a key and looks up the value for that key in itself. Also keywords (e.g. :this-is-a-keyword) are functions that look themselves up in a map.

agile_geek15:11:07

i.e. ({"key" "this works"} "key") => "this works" and (:key {:key "this works"}) => "this works" both work

agile_geek15:11:04

but this ("key" {"key" "this throws exception"}) doesn't

agile_geek15:11:42

as "key" is just a java.lang.String which doesn't implement IFn i.e. it's not a function

roelofw15:11:25

@agile_geek thanks for the explanation

roelofw15:11:30

That's what I like about clojure. Always people who wants to explain things or help with problems

roelofw15:11:05

@agile_geek did you ever work with boot and if so, which "ide" do you use ?

agile_geek15:11:29

@roelofw I've not really used boot, mainly lein and I use Emacs but I have friends who much prefer IntelliJ with Cursive (and some who use Vim and Fireplace or Spacemacs)

agile_geek15:11:47

However, Emacs is a steep learning curve all of it's own

roelofw15:11:49

Oke, I use Cursive but I like to try this framework : https://github.com/framework-one/fw1-clj

roelofw15:11:03

but I seems to only be working with boot

agile_geek15:11:08

There's no reason boot can't be used in Cursive but I've no idea how. Might be worth posting a specific question in the #boot channel?

agile_geek15:11:46

i.e. "I'm a beginner using Cursive. How do I get started with Boot?"

agile_geek15:11:44

or conversely ask in the #cursive channel!

roelofw19:11:52

Im stuck at 4clojure , challenge 156 , I have to solve this :

(= (__ 0 [:a :b :c]) {:a 0 :b 0 :c 0}) 
. I thought this would solve it :
(fn [v m](map (assoc % v) m )) 
but now the % is unknown

roelofw19:11:05

anyone a tip how to solve it ?

tom19:11:18

@roelofw do you mean #(assoc...)?

roelofw19:11:26

Could be . What I try to do is to add the zero to every item of the list

roelofw19:11:41

that is why I have used a map

roelofw19:11:07

@tom : you mean that I have to use a anymious function .

roelofw19:11:29

And then the current item . can I call that item ?

dpsutton19:11:27

the % is for the parameter for anonymous functions of the style #(function-name %). since you are using the (fn [param1 param2] ...) you use whatever you named your parameters

dpsutton19:11:34

in your case, you called them v and m

roelofw19:11:49

@dpsutton so I do not need a map ?

dpsutton19:11:13

i'm just telling you why the % doesn't work in the (fn [v m]) style

dpsutton19:11:19

what functions you need are up to you

dpsutton19:11:24

i'm solving your syntax issue

roelofw19:11:36

No problem thanks