Fork me on GitHub
#beginners
<
2018-09-28
>
enforser00:09:59

oh wow, I had no idea the :>> tag exists. Going to use that all the time. I think using #(%2 %1) would be a little more clear - as then it's purely up to if the provided function returns truthy - so you could have something like nil? :>> do-something

enforser00:09:20

that's great though! thanks @mfikes

sb08:09:19

I would like to use in clojurescript npm dependencies. That works in figwheel but I can’t load in the namespace. Example: https://github.com/kapware/lein-cljs-npm-deps-example how I tried:

(ns lein-cljs-npm-deps-example.core
  (:require ["left-pad" :as lf]))
what I got:
#object[ReferenceError ReferenceError: module$Users$sb$Desktop$test$lein_cljs_npm_deps_example_master$node_modules$left_pad$index is not defined]
nil

sb08:09:09

I found out.. (:require ["left-pad" :as leftPad]))

sb08:09:25

I need to use the function name as name…

Digital Baboon08:09:56

This may seem stupid, but I have a set of routes within which I'd like to load some code from a separate .cljs file. Let's say my core.cljs is: (defroute home-page "/index.html" [] (include-file "home-page.cljs")) and the code I'd execute is in the home-page.cljs, is that possible?

Digital Baboon08:09:41

The include-file is an example of how I'd see it be a thing, it isn't an actual function.

justinlee16:09:40

@im are you talking about trying to code split and load code dynamically like in a pwa?

borkdude16:09:10

@im you can (require '[home-page :as hw]) and then call any function from that namespace with (hw/some-function)?

Digital Baboon16:09:49

@lee.justin.m @borkdude Yup exactly, I figured it out and have now mastered namespaces! Clojure is amazing.

jimbob18:09:15

any good articles discussing tradeoffs between monads and exceptions in clojrue for “error” handling?

jimbob18:09:38

or anyone have any strong opinions one way or another?

lilactown18:09:43

I prefer exceptions ¯\(ツ)

lilactown18:09:12

better language support for it. decent performance.

noisesmith18:09:59

the thing is, exceptions and monads aren't your choices, your choices are exceptions, or monads and also exceptions

noisesmith18:09:16

because you can't eliminate exceptions, they are part of how the vm operates

borkdude18:09:05

@eval2020 made a nodejs / cljs library where he uses the pattern [err result] in combination with core.async, I think mainly because throwing exceptions in core.async is hard to handle https://gitlab.com/eval/otarta/blob/master/src/otarta/main.cljs#L66

borkdude18:09:47

but in “normal” clojure code, exceptions is the most common form of error handling

hiredman18:09:50

I think it really depends on if your code is dealing with aggregates or not. if you are building lots of pipelines basically mapping and reducing stuff, returning some value that is either an error report or data, and having the error value passed through subsequent steps to be collected and reported at the end is very useful

borkdude18:09:11

agreed. also for validating data that’s a useful pattern

lepistane20:09:56

hello i have a problem with ClojureScript it's not a problem but i fail to solve this. I am doing interoop with google maps function looks like this

(when condition
              (doseq [[index item] (map-indexed vector lazy-seq-of-variable-lenght)]
                (.setPosition (get (:markers @gmap) index)
                                    (js/google.maps.LatLng. (:lat item) (:long item))))

              (.setPosition (:solo-marker @gmap) (js/google.maps.LatLng. (:lat solo) (:long solo)))

         )
i've made same amount of markers and added them to gmap atom the idea is to .setPosition to all of them based on item's lat and long but nothing happens. Now i do get .setPosition will be executed inside in doseq is there a way for doseq to just pass .setPosition to when function so it's executed there? There must be...

jaawerth20:09:19

@lepistane while you could put when inside of doseq, doseq` also supports the same additional binding and filtering options as for (see the docs on for for more info), so you could use :when to filter it as need be. For example: (doseq [x (range 1 11) :when (= 0 (mod x 2))] (println "x: " x)) prints just 2, 4, 6, 8, 10

lepistane20:09:09

@jesse.wertheim - that is understandable but it's not needed for my use case. Biggest question is how to execute .setPosition inside when basically return functions to be executed in scope above. It doesnt' matter which function is scope above

jaawerth20:09:46

I guess I don't understand what you mean. when is just a macro that evaluates its body when a condition is passed

lepistane20:09:12

aha, sorry so the main thing is to 1. generate functions that need to be executed 2. return them 3. execute them number of generated functions will vary

jaawerth20:09:44

Ah. In that case you could just use either for, map, or something similar to create a lazy-seq of functions to execute. IF they're all just different invocations of .setPosition, you could use either partial or the anonymous function macro to wrap the invocation based on whatever params you have. You could further abstract it by making a dedicated "function factory" if need be but I'd probably start by doing it directly

lepistane20:09:31

i tried with for it just returns the list of functions but they don't seem to be executed

lepistane20:09:09

(when condition
              (for [[index item] (map-indexed vector lazy-seq-of-variable-lenght)]
                #(.setPosition (get (:markers @gmap) index)
                                    (js/google.maps.LatLng. (:lat item) (:long item))))

              (.setPosition (:solo-marker @gmap) (js/google.maps.LatLng. (:lat solo) (:long solo)))

         )
something like this

jaawerth20:09:11

I thought that's what you wanted? for sould be to give you steps 1 and 2, step 3 would be running doseq on the sequence of functions to execute them

jaawerth20:09:19

I see. So you want, when that condition passes, to both iterate your lazy-seq, invoke .setPosition on each one, and - separately from that iteration but still only if the condition passes, also call .setPosition on that solo marker?

jaawerth20:09:24

If so, why wrap the .setPosition in their own functions?

noisesmith20:09:38

with the when like that, the for is a no-op, it's lazy and nothing consumes what it returns

jaawerth20:09:10

for produces a lazy-seq that needs to be consumed, which works out if you need to create a bunch of functions you want to execute lazily at al ater date, but there's little point if you want to do it all at once

lilactown20:09:24

I think the issue that @lepistane needs help with isn’t the for loop, it’s that his doseq isn’t making the markers show up on his map

👍 4
noisesmith20:09:59

for isn't a loop :P

lilactown20:09:12

he was a bit confused how when works but that’s not the problem

lilactown20:09:41

😛 okay sure. old turns-of-phrase die hard

jaawerth20:09:44

ahh yeah, the question about when threw me off. I've never used the google maps api but I would suggest simplifying the problem by testing the use of setPosition and the logic around it separately

lepistane20:09:33

i just want to have multiple markers i made it work with just just

(.setPosition marker1 ...)
(.setPosition marker2
(.setPositon marker3 
....
i just want to abstract that so no matter how many marrkers i have they are all set in this fashion

jaawerth20:09:47

I see. Your original code with doseq doesn't have any glaring issues jumping out at me, though, so my guess is either the condition isn't passing for some reason or there's something off about what's getting passed to setPosition or stored in the atom

jaawerth20:09:53

It's a bit tough to tell out of context though

lepistane20:09:25

funny thing is .setPosition for soloMarker does work but doseq dont that leaves only the doseq part not doing what i want it to do

jaawerth20:09:23

Right, so I would first verify that the doseq body is iterating, and index, and item are what you expect by either writing a test or just adding a println to the doseq body. Once you've verified that, the likely culprit is going to be something about what you're trying to pull from the atom for use with .setPosition

mfikes20:09:35

What does your code with the doseq look like? (I don't see it in the backlog.)

mfikes20:09:59

So, sorry, a few screens back 🙂

jaawerth21:09:34

@mfikes I'm going by what's in https://clojurians.slack.com/archives/C053AK3F9/p1538165576000100 but it may have changed since then

lepistane21:09:08

i will remove atom pulling now

lepistane21:09:41

thank you all for your help actually it's rather ... i actually didn't bind markers to google map no wonder they weren't showing time to sleep now xD

jaawerth21:09:34

😄 it happens!

peter-kehl21:09:55

@borblytams Your question about http://4clojure.com: It helps to compare your solution to other users. See http://www.4clojure.com/users and "follow" several top users. You can only see their solutions once you complete yours (per exercise), which also gives motivation.