Fork me on GitHub
#beginners
<
2019-11-22
>
solf06:11:28

I'd like to know if two maps are equal but with customizing the equality for functions: I'm just interested in knowing if both values are functions, not if they are the same ones

solf06:11:33

Any way of doing that using is? (it's for testing purposes)

solf07:11:37

I think I'm going to use postwalk to replace all functions by a label in both maps, and test the resulting modified maps

andy.fingerhut11:11:24

If an approach where you can transform your two given maps m1 and m2 into two other maps m1-mod nad m2-mod, and the right answer you want is (= m1-mod m2-mod), works for you, I would definitely recommend that. There is no built-in way to modify how = works on maps. You can write your own recursive comparison function that takes two maps, but then you are responsible for doing all of the recursion cases yourself, on all possible sub-collection types.

keymone13:11:32

i'm missing something obvious with clojure.tools.cli/parse-opts, i have an option defined like this: ["-c" "--config" "description" :default-fn (fn [& _] (System/getenv "CONFIG"))] but parsing it with -c xyz returns {:config true} and xyz as non-consumed arg

keymone13:11:43

what am i doing wrong here?

keymone13:11:44

(parse-opts ["-c" "foo"] [["-c" "--c" nil :default-fn (fn [& _] "bar")]])
;; => {:options {:c true}, :arguments ["foo"], :summary "  -c, --c", :errors nil}
that's the call ^

keymone14:11:50

apparently "--c" is not enough, it should be "--c SOMETHING"

seancorfield14:11:31

@keymone that placeholder syntax is what tells tools.cli that you want a value-based option instead of a boolean option.

seancorfield14:11:16

Happy to improve the docs if you can articulate what would have made that clearer to you?

👍 4
keymone14:11:24

do you accept pull requests on github or is the process different?

seancorfield23:11:37

@keymone PRs on GitHub are good, yes! Thank you.

keymone14:11:16

yeah, i understand that now, it's just easy to miss the importance of it when reading examples and docs

grounded_sage17:11:40

I'm trying to fetch an auth token on the client side in cljs. It is a promise and I want to use that token in a request. But I'm having trouble figuring out how I can make that synchronous.. It's one little thing so I don't think it's necessary to pull in core.async just for this.

hiredman17:11:22

You can't make it synchronous

hiredman17:11:01

You have to do a .then and pass a callback or whatever the js promise thing is

john-shaffer20:11:46

If the JavaScript to import is import { Editor } from '@tinymce/tinymce-react'; , how would I import/reference Editor in ClojureScript? I'm including tinymce-react.js in a <script> tag.

john-shaffer20:11:38

Got something started with cljsjs/draft-js

drewverlee20:11:28

What does derefing a function e.g defn foo []) @foo achieve? with slightly more context #js {:default #(@loadable)}

hiredman20:11:12

Why do you think the loadable name is bound to a function?

drewverlee22:11:48

its probably not, good point.

sysarcher22:11:25

Any ideas folks? https://clojureverse.org/t/setting-image-grayscale-cljs/5114 This might be a greater JS question, but I'm not sure... Any help is appreciated.

lilactown23:11:47

if you’re just using raw CLJS (no frameworks like reagent/hoplon/fulcro/etc.) then might advice would be to add-watch the rawdata/img-data atom

👍 4
lilactown23:11:12

I’m not sure what the relevance of go-loop is unless you have some other core.async machinery that you haven’t posted

sysarcher15:11:52

I'm using reagent... I wnted to do the go-loop thing to update (periodically) whether an image should be grayed or not. The data (as to whether something ought to be grayed out) comes from a REST API

sysarcher15:11:06

Just checked out the answer on Clojureverse. Will check out watches (I have no idea what they are atm 🙂 )

lilactown16:11:11

go-loop involves using and understand core.async and channels and how to use them in your app. it's quite complex

lilactown16:11:27

you can't just use go-loop arbitrarily

lilactown16:11:34

add-watch sounds like what you really want

sysarcher17:11:48

go-loop is working fine for me ... I'm using go-loop to fetch data from a server periodically... Yeah, I'm still a noob when it comes to Clojure and Cljs... add-watch does look like what I'm looking for!! though up until now, calling the styling function inside the watch has no affect.. but if I call it from the REPL, it works just fine :thinking_face:

lilactown17:11:01

try this: change for to doseq

lilactown17:11:20

I bet that is why it wasn't working in your go-loop as well

sysarcher17:11:06

hmm... going to try it right away.. thanks for the tip @U4YGF4NGM

sysarcher17:11:31

@U4YGF4NGM dude... it worked

sysarcher17:11:02

I bet it's the for loop and how I was (mis)using it :man-facepalming:

lilactown17:11:57

For loops are lazy. The code inside it won't run unless it's consumed by something else

lilactown17:11:17

When you ran it at the repl, printing out the results consumed the lazy sequence

sysarcher17:11:49

hmmm... that makes sense!

sysarcher17:11:27

also explains why the "same" thing doesn't behave similarly 😉 Thanks again!!

sysarcher17:11:05

Today was my 12th day of Clojure and Clojurescript and this final thing was the last thing remaining on my quick-learn journey with HTML/CSS/Cljs!! I definitely couldn't have done my app this fast without the community!