Fork me on GitHub

Hello I'm getting a bit confused with js interop again may I ask what L.Polygon(latlngs).bindPopup('Hi There!').addTo(map); is equivalent to syntax wise ?


I would probably write something like:

(-> (L/Polygon latlngs) 
    (.bindPopup "Hi there") 
    (.addTo map))


actually, cljs might require:

(-> L
    (.Polygon latlngs) 
    (.bindPopup "Hi there") 
    (.addTo map))


Okay let me try 🙂 I somehow always feel clojurescript interop is much tougher than java interop


Did you get it to work? What did you try?


Am doing react-leaflet and got what I wanted to do to work for now ...

[:> GeoJSON
    ;; [:> Popup "test"]
    {:data sites
     ;; :color "#ffffff"
     :onEachFeature (fn [feature layer]
                      (do (.bindPopup layer "test")
                          (js/console.log ;; (.. layer -feature -properties)

                      ;; (.bindPopup (leaflet.) "hi")
     :eventHandlers {:click #(js/console.log %)}}]

👍 2

But do you by any chance understand how this might be done?

function MyComponent() {
  const map = useMap()
  console.log('map center:', map.getCenter())
  return null

function MyMapComponent() {
  return (
    <MapContainer center={[50.5, 30.5]} zoom={13}>
      <MyComponent />
I only know how to do this part
[:> MapContainer
 {:center [50.5 30.5] :zoom 13}]


I’m guessing you probably mean to ask about children components (in this case, MyComponent) Something like this should work

[:> MapContainer
 {:center [50.5 30.5] :zoom 13}
 [:> MyComponent]
 ;; You can add as many children as you wish


TBH - you may need to try some variations to get the right syntax, but this is essentially hiccup - multiple children, nested children - these typically work as you’d expect, save for some JS interop nuances.


How do I create MyComponent exactly 😮


Oh wait - I was under the impression you are looking to use some existing JS from CLJS. To clarify - is your question how you’d do everything in CLJS?


I think my questions is how does the syntax of <MyComponent> as well as its creation as a function get translated to cljs


Ok - your examples suggest you are already using reagent MyComponent has no visual part to it. useMap doesn’t seem to refer to any pre-existing state. You may probably want to explain the purpose of MyComponent some more?


But do you by any chance understand how this might be done?

function MyComponent() {
  const map = useMap()
  console.log('map center:', map.getCenter())
  return null

function MyMapComponent() {
  return (
    <MapContainer center={[50.5, 30.5]} zoom={13}>
      <MyComponent />
I only know how to do this part
[:> MapContainer
 {:center [50.5 30.5] :zoom 13}]


What's a more idiomatic way to use the function map inside the function map

Dongwook Kim07:07:58

(->> (map #(+ 1 %) [1 2 3])
     (map #(* 2 %))
something like this? I'm not sure, it's idiomatic way


right think that makes things a bit better 🙂


map keeps one-to-one correspondence, so a comp may be a good option to use

(->> [1 2 3] (map (comp #(* 2 %) #(+ 1 %))))


Yeap! Okay!


I am a newbie developer. This might not be as clojure specific and more of a design question,: I want to separate my business logic and persistence logic into two namespaces. Currently its a mix. I have a namespace (lets call it ns1) that calls some upsert functions in another namespace (ns2). However, these functions in ns2 contain business logic, checks and validation and also upserts data into the database. This is a lot of responsibility of a single function, therefore i want to split them out. My idea was to create an additional namespace and basically have all data access happen in that. So ns1 will call ns2 which handles all the business logic and validation of the data and then calls ns3 which actually inserts, upserts, fetches the data. Does this sound like a solid idea? Another problem is the naming of these functions. Currently all functions in ns2 are named something like "upsert-placeholder-into-db" But when i remove the upsert functiontionality from ns2 into ns3, what would i call the ns2 function then? From the perspective of ns1 it would look weird that i call some "handle-placeholder" function when all i really want in n1 is to just insert the data. Maybe i am overthinking this. Sadly i cant' show you any of the code

Jon Boone12:07:15

Hi @U01GQRC8W30 — this is, as you suspected, not a strictly Clojure related question. May I ask what purpose the functions in ns-1 serve?


think of your names as fully qualified. it helps you to find good names. Say you define a dbnamespace. then db/insert is a sufficiently descriptive name, so you just say (def insert …)

Jon Boone12:07:45

Are the json files received over http?


ns2 here would be something like model I think


that would be a traditional name for code that handles validation, marshalling and buisness logic on top of data base records.


you can then say model/insert and db/insert! where the former is just a function and the latter does the actual transaction. But that is just an example to showcase how the namespace belongs to the name.

Jon Boone13:07:12

I’d recommend reading this article about Clojure web app frameworks:

👍 2

not necessarily. there is a common design principle in clojure to avoid side effects and state. so ns2 would just be functions from data->data. ns3 would do the side effects.


this way you can lift the state up, make it visible


Hello, I am using to get my clojure backend to execute a python script and using :out (as in the print) to get the output. Previously, while perhaps not the most ideal option, this has worked for simpler outputs However, I currently have a script that prints out some initialisation and takes awhile - under a min to a few minutes to finish printing. This causes to return before my script has completed. Is there a way to approach this?


ProcessBuilder is easy to use, it returns an outputstream or outputs to a file instead of giving you a string directly though something like: (-> (ProcessBuilder. ["python" "-flag" ""]) (.start) (.waitFor)) gives basic execution


this version shouldn't be hard to adapt for python:

(let [pb (ProcessBuilder. ["lua"])
      p (.start pb)
      out (.getOutputStream p)
      in (.getInputStream p)]
  (spit out "print \"hello from lua\"\n")
  (slurp in))


(it also demonstrates sending real time input to the process, you could even interact while the process runs based on its output...)


Here’s what I’d guess - the stdout isn’t flushed on program end, which leaves some of the output hanging. Depending on what python function you are using to print, try ensuring stdout flush as the last step before end?


You mean I should find a way to withhold output until everything is finished ?


what does :exit have in it?

👍 2

wait I think you are right .... I am getting an output cause my script has issues


Please share what you find.


oh as in :exit is 1. And realised my script was encountering errors and hence was returning ... let me fix my script first

👍 2

how to get [:a :c :a :c :a] given ((fn _) [3 :a :c])?


how does [3 :a :c] translate to [:a :c :a :c :a] i would understand i think if there was another :c at the end. and you want the arguments repeated 3 times


my clumsy onee: (butlast (interleave (repeat 3 :a) (repeat 3 :c)))


(apply concat (take %1 (cycle %&))) I think


oh yeah, the lack of :c at the end makes this one fail


I don’t think its clumsy at all


(defn g [n & items]
  (butlast (into [] cat (repeat n items))))
can handle arbitrary number of items. (g 3 :a :b :c) etc


but i think your version was fine if you know its only two arguments


thank you both!


Hello, how do I read a vector of python dictionaries as string. Like [{'a': 'test' , 'b': 'test}, {'b' : 'test'}, {'c' : 'test'}] in clojure?


Convert Python dictionaries that you have as string to a vector of Clojure hashmaps? Is my understanding correct?


You'll have to roll your own parser or use something like


There is also if you want to do the conversion of data structures residing in memory rather than reading from a file


Or convert to an intermediary format (a conversion that you trust) like JSON and read that into Clojure


I formatted it to edn and used edn/read-string just need to do some key to keyword conversion i guess


Oh I thought you would be reading a lot of these, didn't know it was a one-off use case 😅


It is a fixed python script I am running and processing into my clojure backend i guess


Is there a good way to convert/rename keys as strings to keywords


Thanks! I only knew of the latter option 🙂


Yeap keywordize-keys is exactly what i was looking for!

Rob Haisfield19:07:10

(#(re-seq #".md" %) "")
I’m trying to get the part that is not .md

Rob Haisfield19:07:29

My naive pseudo-code implementation would be this, but it doesn’t work

(#(re-seq (not #".md") %) "")

Jo Øivind Gjernes14:07:07

(first (str/split "" #"\.md"))

Rob Haisfield19:07:42

How do I get the parts that aren’t .md?


@U02108ERRU5 Like this you mean?

dev=> (second (re-find #"(.*)\.md" ""))

Rob Haisfield19:07:28

Awesome, thank you!


@U02108ERRU5 are you using the REPL?

Rob Haisfield19:07:36

@U050ECB92I am using the REPL. Why do you bring it up?

Rob Haisfield19:07:14

(def test ["" "" ""])

(map second (map re-find #"(.*)\.md" test))
Okay now I’m trying to extend that function to a list of strings and it’s not working, I’m not sure what Im doing wrong


(map second (map #(re-find #"(.*)\.md" %) test))

Rob Haisfield20:07:48

Okay that works for the list… so @U04V70XH6, what am I missing? Why does that work and what I did at first not work?


take a string that you are saying it's not working on and try it in the repl. (re-find #(.*)\.md "some-string.markdown") or whatever and see what it returns


Because (map re-find #"(.*)\.md" test) is calling map with three arguments as if it were (map func coll1 coll2)


Which is not the same as (map #(func coll1 %) coll2)


oh right 🙂 that


Try (map vector [1 2 3] [4 5 6]) and (map #(vector [1 2 3] %) [4 5 6]) and you'll see the difference.

Rob Haisfield20:07:04

Ohhhh okay that makes sense, thank you for the explanation


If I have some namespace A, that provides some function f, and I want to make a new namespace B that provides the same function, what would the best way to go about it be?


Right now I can imagine:

(ns B
  (:require [A]))
(def f A/f)
But is there a better way?


You'll lose metadata on f doing that. I guess the question is: why do you want to do this?


(re-exporting vars from nses is a bit of a code smell, IMO)


The short answer is because I have to. The longer answer is because in this case, module B isn't actually written in clojure(script), but happens to satisfy the namespace protocol.


But because I want the effect of the code analyzer, I want to reprovide it from another module that is written in clojurescript.


If I have to, I can also write full blown wrapper functions to reify error checking done by B/f


I'd just be nice to not have to.


As long as you don't care about metadata, (def f A/f) is probably sufficient. If you do care, you'll need something fancier that copies across the metadata into the B ns... but I'm not sure what that would look like in ClojureScript.


Eh, okay, thanks. Since B is sort of side-loaded into my environment there isn't any metadata (so it has to be provided by A anyway), so thanks. 🙂

Rob Haisfield21:07:06

(defn find-name-in-name [name1 name2]
  (re-seq (re-pattern name1) name2)) ; okay so this works

(find-name-in-name "GIF" "animated GIF for GuidedTrack")
I’m trying to figure out how to make it so if name1 appears in name2, it will return name2. Currently, the function just returns name1. Any advice?

Rob Haisfield21:07:29

I figured it out!

(defn find-name-in-name-experiment [name1 name2]
  (if (not (nil? (re-find (re-pattern name1) name2)))


(and (re-find (re-pattern name1) name2) name2)


Or (when (re-find (re-pattern name1) name2) name2) if you prefer.


(if (not (nil? x)) y z) is just (if x y z) BTW


(except when x is false -- but in this case they'd be the same)


What is a good way to get started using clojure with powershell scripts?


@wme.weeks Can you elaborate? I'm not quite sure what you're asking...


Do you mean "How can I install Clojure so I can use it from the Powershell command-line?" -- if so, try


Or is this a java shell interop question?