Fork me on GitHub
#beginners
<
2015-11-04
>
dexter17:11:38

I’m having some problems with working out why I have a lazy seq

(defn map-rewrites [rewrite-rules] (doall (map (fn [[k v]] (doall (str ".addRewriteRule(\"" k "\", \"" v "\")"))) (doall (seq rewrite-rules)))))
(defn map-matches [match-rules] (doall (map (fn [[k v]] (doall (str ".addMatchRule(\"" k "\", \"" v "\")"))) (doall (seq match-rules)))))
(defn map-remapping [{:keys [match rewrite]}] (doall (str "remapping(remappingBuilder.reset()\n" (doall (map-matches match)) (doall (map-rewrites rewrite)) ");")))
(doall (map println (map map-remapping remappings)))
Where remappings looks like:
[{:match {:api_key "doubleclick", :google_error nil}, :rewrite {:partner_user_id nil, :id_space "d”}}]
I dont think there is anywhere left for me to put doall but still its a lazy-seq:
remapping(remappingBuilder.reset()
[email protected]@4da99836);

surreal.analysis17:11:59

@dexter: I don't think doall actually converts things from a lazy-seq

surreal.analysis17:11:02

user=> (type (doall (lazy-seq [1 2 3])))
clojure.lang.LazySeq

surreal.analysis17:11:18

However, it should be printing out all of the relevant lines

surreal.analysis17:11:45

I'd get rid of all doalls but the last one (map println)

dexter17:11:33

its definitely not printing anything out

dexter17:11:49

I’ve discovered why I think though

dexter17:11:25

the map-matches and map-rewrites functions both actually return lists of strings

dexter17:11:04

if I switch map to mapcat it gets fractionally further, materialising all the strings as a huge list of single chars

dexter17:11:24

but then as soon as I try to concat them into a string it goes back to being lazy

surreal.analysis17:11:03

Can you post the code with the doalls removed?

surreal.analysis17:11:36

Also, instead of mapcat, try

(flatten (map f col))

dexter17:11:54

(defn map-rewrites [rewrite-rules] (map (fn [[k v]] (str ".addRewriteRule(\"" k "\", \"" v "\")")) (seq rewrite-rules)))
(defn map-matches [match-rules] (map (fn [[k v]] (str ".addMatchRule(\"" k "\", \"" v "\")")) (seq match-rules)))
(defn map-remapping [{:keys [match rewrite]}] (str "remapping(remappingBuilder.reset()\n" (map-matches match) (map-rewrites rewrite) ");"))
(map println (map map-remapping remappings))

surreal.analysis17:11:30

Do you have example remappings?

dexter17:11:44

[{:match {:api_key "doubleclick", :google_error nil}, :rewrite {:partner_user_id nil, :id_space "d"}}]

surreal.analysis17:11:51

Oh, right, missed those. Thanks

dexter17:11:19

so I think doing (apply str (map-matches match)) instead of just (map-matches match) solves it

dexter17:11:49

so that str is operating on 4 strings instead of two lists of strings and two strings

surreal.analysis17:11:01

Nice, glad to hear it

dexter17:11:47

ty for the help

roberto17:11:37

ah, if you are doing any sort of side-effecty thing, put it inside a doseq

roberto17:11:15

so instead of (doall (map println (map my-fn my-coll)))

roberto17:11:44

do (doseq [coll (map my-fn my-coll)] (priintln coll))

roberto17:11:54

it is not recommended to do a println inside a map

roberto18:11:05

or any type of IO.

surreal.analysis18:11:26

Hmm, @roberto If true, someone should update the docs

roberto18:11:51

yeah, but he had (doall (map println (map my-fn my-coll)))

roberto18:11:15

if he wanted to print the entire coll: (doall (println (map my-fn my-coll)))

roberto18:11:20

instead of that extra map

roberto18:11:27

the side effect fn is println

roberto18:11:37

map shouldn’t have any side effects

surreal.analysis18:11:43

Oh, nevermind, I don't get it

surreal.analysis18:11:01

If you look at the documentation, it suggests that println is the most common use of doall

roberto18:11:22

ah, I jus saw the example, that has never worked for me

surreal.analysis18:11:24

All of the examples are (doall (map println col))

roberto18:11:25

ran into bugs with that

meikemertsch18:11:02

Does anyone know more about OAuth in Clojure? I am generally an oauth failure as I still can't handle it. Even Clojure doesn't make it better. After trying around with clj-oauth and oauth-clj I am feeling even more stupid... How do I get this http://apidev.bricklink.com/redmine/projects/bricklink-api/wiki/Authorization to work with Clojure? I probably need the explanation in a format fitting for a ten-year-old 😥

meikemertsch18:11:51

Oh. It's OAuth v1.0 and I don't have any signing URIs ...

roberto19:11:01

what are you using as your provider?

roberto19:11:13

I’ve been able to use oauth with both Heroku and Google as my providers.

roberto19:11:38

if you are using Google, this is a very convenient library https://github.com/Mayvenn/friend-google-openid

meikemertsch19:11:07

I'll look into it, thanks

upgradingdave19:11:38

I’d like to use immuconf which defines some reader tags here

upgradingdave19:11:10

when I experiment from the repl, I’m getting a java.lang.RuntimeException: No reader function for tag immuconf/override

meikemertsch19:11:40

Hm.. It seems that doesn't solve my problem. It's 'just' about the Auth header. What I am doing is programming against bricklink's API. I don't think I have a provider there

upgradingdave19:11:42

do I have to move that data_readers.clj file out of immuconf and put it inside my project’s src dir?

upgradingdave19:11:52

figured out I can do this so that it works in the repl

upgradingdave19:11:22

I wonder why the repl doesn’t seem to recognize the data-readers.clj that’s inside the immuconf jar? Oh well, moving on!