Fork me on GitHub

Hi, what is the meaning of this - convention in function names like -main? thx


AFAICT, (defn -main ...) defines a static method "main" in the declared namespace.


hm, static method sounds like a oo term.


@schmee @penryu that was the missing link! Thank you!

😊 4

@wactbprot Not to be confused with the (def- foo ...), which defines a function "foo" which isn't exported when performing (require ...)


Hi everyone! I'm playing around with clojurescript/re-frame, and coming from javascript I have some trouble finding elegant solutions for some things. I'm trying to render the elements of a vector into individual divs. There must be a better way than this - any tips? (I'm mostly bothered by the identity function in the mapping function) ´´´ (map-indexed #(identity [:div {:key %1} %2]) @myvectorofstrings ´´

David Pham10:09:27

did you try the vector function?

David Pham10:09:57

In this case it could be `#(vector :div {:key %1} %2)


@publicz it might be better to use (fn [..] ..) syntax instead of the #(...) shorthand. Then you can avoid identity. Also a neat trick is that you can give map multiple collections. I'm using it here to provide both the vector of strings and an infinite sequence of numbers.

(map (fn [s idx] [:div {:key idx} s]) ["a" "b" "c"] (range))


I'll play with this a little, thanks!


That's awesome, thanks to both of you!


I'm trying to catch an exception and confused why this isn't working (I have caught exceptions before with no problems).


This is the exception tws.core=> *e #error { :cause "CSV error (unexpected character: c)" :via [{:type clojure.lang.ExceptionInfo :message nil :data #:clojure.error{:phase :print-eval-result} :at [clojure.main$repl$read_eval_print__9068 invoke "main.clj" 419]} {:type java.lang.Exception :message "CSV error (unexpected character: c)" :at [$read_quoted_cell invokeStatic "csv.clj" 37]}] :trace [[$read_quoted_cell invokeStatic "csv.clj" 37] [$read_quoted_cell invoke "csv.clj" 23]


Have tried this - (but it fails to catch) tws.core=> (try (csv/read-csv s :separator \tab) (catch Exception e (println "retry"))) Error printing return value at (csv.clj:37). CSV error (unexpected character: c)


And also this (which fails) (try (csv/read-csv s :separator \tab) (catch clojure.lang.ExceptionInfo e (println "retry")) (catch Exception e (println "dd")))


I know the general form I'm using seems to be correct, because this works tws.core=> (try (/ 1 0) (catch Exception e (println "retry"))) retry nil


Any ideas?


Thanks in advance for any help!

dpsutton15:09:51 read the docstring of csv/read-csv. I bet it returns a lazy seq. You need to evaluate everything inside of the try block


@dpsutton thx very much. this works tws.core=> (try (doall (csv/read-csv s :separator \tab)) (catch Exception e (println "retry"))) retry nil


I must admit I don't fully understand why I need to fully realise the lazy sequence in order for the Exception to be caught, when my program has stopped and the REPL was smart enough to have identified that there was an Exception thrown (i.e via *e). I will think on this some more and hopefully it will become clearer in time. :thinking_face: . thanks again.


exception catching is stack based, the implicit lambda created by lazy-seq escape the original stack frames that have the handler set


You can think of a lazy-seq as (cons x (fn [] ...)) where calling next / rest etc. implicitly calls the zero argument function. If the lazy-seq leaves the context of your try block, there is no longer an exception catching machine on your stack


Hi there; a simple question for once: on many templates are categorized to be compatible with leiningen and boot. However invoking the respective boot commands such as boot -d boot/new new -t reagent-frontend -n my-app creates what seems to me like pure leiningen project. Does “compatible” here mean nothing more than the ability to use either tool for templating even though the result is wired towards only one of them? If so, do you know of any reagent frontend templates for boot? Many thanks!


@services Correct. Templates produce whatever type of project they were written to produce.


clj-new can create new projects using clj, boot, or lein templates. boot new can use boot or lein templates. lein new can only use lein templates.


If you see a template that has a boot-template artifact, it should produce a boot-based project.


Thanks… no need for me to search for any automagic conversion feature then…


So <project>/boot-template ...


I see… that would be on GitHub I suppose?


No, on Clojars.


The group/artifact are what the project is deployed as / what coordinates you specify to depend on.


I think this might help you -- a Boot template that can use Reagent.


I don't know how up to date / maintained it is.


ok, thanks for clearing that up! I've been a lisper for years but pretty new to the clojure universe…


Ah, so the JVM will be a whole new learning experience for you...


Well… I've dabbled in Java at least enough to understand thrown errors etc… It's just that all I've done in Clojure so far has been with leiningen… and the tutorials I follow all use boot and the concept makes sense so I wanted try it properly


Anyway, thanks for the reference. This channel is pure gold for newbies!


At work, we started with Leiningen back in 2011 as it was the only thing available. We switched completely to Boot in 2015. Last year we switched completely to the Clojure CLI/`deps.edn` stuff.


Ok, I knew there was a third one… but since all my previous programming went along without any build tools at all and I had a lot of new stuff to learn I thought I'd pick one of the more established ones… anyway I've no successfully used the tenzing template and even got it to work on Java 11 ba updating and adding some dependencies… happy coding!


Hi everyone, what is the best guide for building a clojurescript app? I will be targeting node. I have come across a number of articles, but not clear on what best practice is for deploying. Is it to zip the out directory?


@javazquez so starting off with - I totally know what you're after. what I've learned is that whereas you can find some guidance on practices, with this community (clojurescript on node being a niche within a much smaller community), you're likely going to have to make a lot of your own best practices there and recommend them back. this is 1) great for you!, 2) demands a lot upon you if you want to commit to this!, and 3) enables you to enter into a small community of people also figuring out that same thing. anyway, to directly guide your question, I think the lumo and planck people are most thinking about your problem, although shadow-cljs supports the target you're after as well.


and this is just a general reaction to "what's the best way to do x, y, z in clojure? why hasn't this guide been written yet?" - if you want something, make it, and you will find or create the community you want.


also, I'd probably compile it into a single JS file and stuff it in a docker container or use ncc to pop it into a binary


Thanks @gerred! Appreciate the information. I suspected that was the case, but I have been a way from clojurescript for a bit and didn’t want to reinvent a wheel 😃


for sure 😄

👍 4

it's been heavy on my mind lately so it was a great opportunity to diatribe for a paragraph 🙂


because I don't think my one-liner answer of single JS or ncc is the right answer for all of the right versions of your question, and I care about other things (k8s, cloud native) day to day, but am super compelled once that answer is invented!