Fork me on GitHub
#beginners
<
2019-09-22
>
wactbprot07:09:47

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

penryu07:09:07

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

wactbprot08:09:17

hm, static method sounds like a oo term.

wactbprot08:09:49

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

😊 4
penryu08:09:59

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

coder4633409:09:20

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)

valtteri10:09:59

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

coder4633411:09:58

I'll play with this a little, thanks!

coder4633410:09:51

That's awesome, thanks to both of you!

smp13:09:31

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

smp13:09:02

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 [clojure.data.csv$read_quoted_cell invokeStatic "csv.clj" 37]}] :trace [[clojure.data.csv$read_quoted_cell invokeStatic "csv.clj" 37] [clojure.data.csv$read_quoted_cell invoke "csv.clj" 23]

smp13:09:28

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 clojure.data.csv/read-quoted-cell (csv.clj:37). CSV error (unexpected character: c)

smp13:09:52

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

smp13:09:23

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

smp13:09:47

Any ideas?

smp13:09:58

Thanks in advance for any help!

dpsutton15:09:51

@s.page read the docstring of csv/read-csv. I bet it returns a lazy seq. You need to evaluate everything inside of the try block

smp15:09:31

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

smp15:09:52

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.

noisesmith17:09:46

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

noisesmith17:09:05

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

oliver20:09:43

Hi there; a simple question for once: on http://clj-templates.com 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!

seancorfield21:09:37

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

seancorfield21:09:25

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.

seancorfield21:09:40

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

oliver21:09:59

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

seancorfield21:09:00

So <project>/boot-template ...

oliver21:09:28

I see… that would be on GitHub I suppose?

seancorfield21:09:45

No, on Clojars.

seancorfield21:09:13

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

seancorfield21:09:29

I think this might help you https://github.com/martinklepsch/tenzing -- a Boot template that can use Reagent.

seancorfield21:09:02

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

oliver21:09:29

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

seancorfield21:09:48

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

oliver21:09:11

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

oliver21:09:02

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

seancorfield21:09:20

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.

oliver22:09:56

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!

javazquez23:09:38

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?

gerred23:09:18

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

gerred23:09:47

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.

gerred23:09:23

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

javazquez23:09:24

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 😃

gerred23:09:28

for sure 😄

👍 4
gerred23:09:42

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

gerred23:09:19

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!