Fork me on GitHub
#beginners
<
2017-01-23
>
seancorfield05:01:56

@simon Do you want to post that StackOverflow link in here so folks can take you through things step by step?

seancorfield05:01:55

I see Alan Thompson has replied to your question on SO @simon -- if you have any questions about his response, feel free to ask them here and folks should be able to walk you through...

seancorfield05:01:27

(but do remember it's nearly 10pm on West Coast of the US right now so not too many people will be around for a few hours! 🙂 )

okwori06:01:07

The special form (.. part was helpful BUT my setup doesn't recognize the forv function

beppu06:01:20

@simon You want to use map - https://clojuredocs.org/clojure.core/map

(map (fn [n] (calculate-distance-matrix 2 (define-context API-KEY) n)) (get-place-types))

val_waeselynck08:01:20

@abarylko and the error message is?

abarylko17:01:45

@val_waeselynck error: package com.fasterxml.jackson.databind does not exist in import com.fasterxml.jackson.databind.*;

val_waeselynck18:01:17

@abarylko probably a classpath issue => use lein deps :tree to debug it

abarylko18:01:26

@val_waeselynck I see this in my deps [com.fasterxml.jackson.core/jackson-core "2.8.6"]

gdeer8120:01:54

wondering if I'm doing configuration wrong. config.edn has a map of with keys to function names, in the clj file the functions are defined, then the config file is loaded into a var, but when trying to use the function by dereferencing the key from the config map, it doesn't do anything. so {:afun some-fun} gets loaded into my-config after some-fun is defined in the namespace but then (def fun-results (map #((:afun my-config) % 10) some-list)) doesn't do anything. storing function names in a config file so you can swap out different functions for different environments seems like a pretty common use case. I might have made some silly 4am mistake but I figured I'd ask in beginners chat since for learning purposes

gdeer8120:01:49

(let [configured-fun (resolve (:afun my-config))] (map #(configured-fun % 10) some-list))

gdeer8120:01:00

I'm using clojure.edn/read-string to load the config which is safer than clojure.core/read-string which is why I have to do the extra step to resolve the function name

gdeer8121:01:41

I guess I could use clojure.core/read-string since I trust the person that is writing the config file (me)

seancorfield22:01:33

There’s no harm in resolving at runtime — and maintaining the safety of reading via pure EDN.

seancorfield22:01:42

Are the functions in the same namespace?

seancorfield22:01:00

If not, you probably need to require their namespace before the resolve.

seancorfield22:01:06

(I’d be very wary of (def fun-results …) since that will execute at load time — or worse, compile-time if you AOT — and that is almost certainly not when you want that to execute)

seancorfield22:01:30

You almost never want def with anything more that a very simple expression.