Fork me on GitHub

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


that's great though! thanks @mfikes


I would like to use in clojurescript npm dependencies. That works in figwheel but I can’t load in the namespace. 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]


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


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.


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


@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.


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


or anyone have any strong opinions one way or another?


I prefer exceptions ¯\(ツ)


better language support for it. decent performance.


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


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


@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


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


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


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


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...


@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


@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


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


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


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


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


(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


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


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?


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


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


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


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

👍 1

for isn't a loop :P


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


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


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


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


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


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


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


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


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


So, sorry, a few screens back 🙂


@mfikes I'm going by what's in but it may have changed since then


i will remove atom pulling now


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


😄 it happens!


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