Fork me on GitHub
#clojure
<
2019-10-28
>
Arto Kalishian08:10:08

Is there a more pure way to learn web development with CLJS rather than Luminus? I feel like starting with no framework at all will better teach me how to fit components but I'm not sure which guide/book teach that?

Arto Kalishian08:10:07

Coincidentally someone just posted on reddit something similar to what I'm asking for: https://www.reddit.com/r/Clojure/comments/dnwldr/a_series_of_tutorials_on_creating_a_fullstack_app/?utm_medium=android_app&amp;utm_source=share But still if you have other options please mention.

Ruben Serradas08:10:47

Not sure about ClojureScript, but have you tried with the first edition of Web Development with Clojure? It guides you through the different libraries available for clojure web development.

Arto Kalishian08:10:20

Interesting, from what you say I'm assuming that the first edition doesn't use luminus...

👍 1
Arto Kalishian08:10:46

I might try it for sure if that's the case.

jumar08:10:35

Warning: I wrote all of these before noticing that it's about clojurescript, not necessarily clojure ----- I'd start with ring + compojure. Read the docs, pick up some tutorials and check sample apps. Web Dev. with Clojure may still be helpful (some parts of it) - thinking actually about the second edition. It may also help to mix in some component (https://github.com/stuartsierra/component) @seancorfield’s example project: https://github.com/seancorfield/usermanager-example/ is pretty useful I think Of course, it depends on what you have in mind since "web development" may mean many different things

👍 1
Arto Kalishian08:10:51

I want to build a simple website project that has a simple 3 table sql database. Not thinking about react for now so as not to add complication. Once I can do that with basic components html css cljs compojure ring postgres I'll probably check how to convert it into a react app. I hope that this sequence of training will teach me the most and then when I use something like luminus I'd appreciate their best practices understanding the reasons behind them.

Chris08:10:00

I found this guide very helpful for starting out: https://devcenter.heroku.com/articles/clojure-web-application

👍 1
grierson11:10:13

I there a way to integrate clojure.spec/check and clojure.test.check/defspec or use defspec tests within spec :fn? I don't want to duplicate some property tests in my test file and some in my s/defspec

Filipe Silva13:10:12

@arto.eg I did https://www.learnreframe.com/ and found it pretty good. There's also a re-frame one that I'm in the middle of.

👍 1
Filipe Silva13:10:47

(this is pure cljs, no clj only)

hosiawak14:10:46

Could someone point me to a guide/tool that I can use to package a bunch of .css files in a webjar please ?

hosiawak14:10:59

I used juxt/pack and depstar but they both copy files directly into the jar and not under META-INF directory

hosiawak14:10:19

which is what is apparently required by webjars

dominicm14:10:52

@hosiawak add a META-INF prefix to your files.

vlaaad14:10:14

META-INF is just a folder

dominicm14:10:16

Eg src/META-INF/foo.css

💯 1
dominicm14:10:43

(There's an undocumented api in pack that could be used to do remapping, but I've not opened it up really. There's not a lot of good in doing clever things with packaging)

hosiawak14:10:54

@dominicm so I need to use a shell script to copy these files into a META-INF directory and then call pack/depstart to package that dir as a jar or is there a tool in Clojure that I can use to do this ?

hosiawak14:10:38

what do they use to process this ?

dominicm14:10:59

Maven supports destdir as an option I think.

hoynk14:10:19

Anybody else getting backend unavailable from http://repo.clojars.org?

hoynk14:10:52

Just started working again, sorry for the spam 😁

futuro15:10:59

Do folks tend to alias clojure.string as str or something else?

dpsutton16:10:04

i like str my work likes string

tws16:10:31

str. I reserve s for spec.

vemv16:10:19

https://stuartsierra.com/2015/05/10/clojure-namespace-aliases life is so much better with this convention having each ns define its own DSL (custom aliases) for refering to other ns'es seems a pretty superfluous barrier for understanding other people's code

👍 1
sova-soars-the-sora16:10:29

templating engines for serverside html ... favorites? currently using rum for cljs and the clj templating, but i'm wondering if there's more mustache-like versions i could be relying on.

seancorfield17:10:39

We use Selmer heavily at work. It's Django-inspired.

dominicm16:10:28

string because why is it special and gets to be str? (Also Stu's thing above)

dpsutton16:10:28

because it is special and gets to be str. 🙂

😂 1
💯 1
danielneal16:10:38

I like it as string but then I always prefer a real word over a shortened or acronym when reading code

dominicm16:10:13

what makes it special though? 😄

bfabry17:10:51

I don’t like str as an alias because there’s a frequently used core fn named str

👍 2
hiredman17:10:01

if you just use the methods on String you don't have to have arguments about namespace aliases

✔️ 1
😂 1
Aleksander17:10:03

can core.match guard/when patterns work across two matched values? this is incorrect syntax but should explain what I have on my mind:

(match [state event]
       [{:limit x}
        {:amount y} :guard (< x y)]  (do-something x y)) 

sova-soars-the-sora17:10:56

I haven't used Django much

futuro18:10:56

Thanks for the thoughts on aliasing all! Solid arguments all around.

carocad21:10:00

does anyone know a “guide/tutorial” out there to create a clojure project that has both Java and Js code ? It seems there are lots of guides for each part but not for both together which makes me a bit afraid 😅

walterl22:10:11

Not a guide/tutorial, but @U04V15CAJ's https://github.com/borkdude/sci has such a mix. I see src-java is referenced in project.clj. Don't know if you need any more than that.

borkdude22:10:52

with lein, to compile java, this is the only thing you need to do

thanks2 1
carocad18:10:29

This is definitely in the direction that I'm looking. However what I meant is rather a project that not only compiles Java but also JavaScript. It seems the project above exports a js file which is not the same 😞

borkdude18:10:45

@UEZDDDLJ1 oh you want to compile JS with CLJ(S) tooling? maybe @U05224H0W's shadow supports this (I wouldn't be surprised)

borkdude22:10:20

another option is to just use additional JS tooling I guess 🙂

ag22:10:15

(-> 1 ((partial = 1))) => true. What’s the elegant way of doing it without inner parens?

seancorfield22:10:30

(->> 1 (= 1)) ?

ag22:10:25

no, I get that… ah. maybe need better example

seancorfield22:10:50

Is this in the middle of a threading pipeline, and you just want "end of args" in this one slot?

seancorfield22:10:01

(-> 1 ,,, (->> (= 1)) ,,,)

bfabry22:10:13

the as-> macro is great for inserting into the middle of a list of -> invocations (`->>` also works if it happens to be you want it last)

ag22:10:18

I’m just looking for equivalent of (), e.g. (-> 2 ((comp + -))), how to do this without inner parens?

ag22:10:48

it’s not apply, it’s not eval, what is it?

bfabry22:10:03

you’re looking for the behaviour where the threading macros insert () for you as a convenience like (-> 1 inc) but for a more complex expression like (comp + -)?

ag22:10:41

yah, something like that

bfabry22:10:15

it does not exist. if the expr in a threading macro is a list then it will not insert the ()’s for you

bfabry22:10:18

is a list at macroexpansion time I guess

seancorfield22:10:40

@ag -> is a purely syntactic transformation. Hence our suggestions to use ->> or as-> in the middle of ->.

ag23:10:56

yeah, I’m just surprised there’s no equivalent to () as in funcall (not as in “unit”, empty list)

ag23:10:33

but just like I was surprised that time when I found, there’s not equivalent of Haskell’s flip function in clojure.core, and soon I learned that you don’t really need it. Probably if that doesn’t exists, it’s not needed

andy.fingerhut23:10:12

What syntax and behavior are you thinking of for () that is not provided by (apply foo) ?

ag23:10:25

you can’t do something like this (->> 42 (comp foo bar baz) apply)

andy.fingerhut23:10:21

Maybe I am too steeped in what -> and ->> do to understand.

hiredman23:10:25

yeah, that doesn't make sense

hiredman23:10:46

I think it would be clearer with a stepped expansion of ->>

andy.fingerhut23:10:34

I am guessing you are not hoping that (comp foo bar baz 42) does something useful?

nmkip23:10:16

Is there a way to try something like (slurp *in*) using the REPL?

hiredman23:10:04

it depends on the repl

hiredman23:10:48

ah, well, I dunno

nmkip23:10:53

But I accept anything that can help me 😛

hiredman23:10:58

there is a #rebl

nmkip23:10:20

I need to parse things from stdin

andy.fingerhut23:10:37

Oh, maybe you were wishing that ->> would somehow figure out on its own that (comp foo bar baz) is a function as a whole, and not stick the 42 inside there?

andy.fingerhut23:10:55

It's not that much of a mind-reader.

ag23:10:11

so these are equivalent, right:

((comp clojure.string/upper-case name) :foo)
(apply (comp clojure.string/upper-case name) [:foo])
(->> :foo ((comp clojure.string/upper-case name)))
so how do you do the last one without inner parens?

andy.fingerhut23:10:36

All of them are absolutely needed

hiredman23:10:43

because ->> is syntatic, not semantic

andy.fingerhut23:10:01

How do you do (+ 5 7) without the parens? 🙂

ag23:10:23

(apply + [5 7])
(apply (partial + 5) [7])

andy.fingerhut23:10:03

I still see parens 🙂

👆 2
hiredman23:10:04

->> doesn't know what the value of the things it manipulates will be after evaluation

hiredman23:10:16

->> only knows what they are after reading

hiredman23:10:30

so it can't test "is this a function"

hiredman23:10:47

it can test "is this a list? is this a number?"

hiredman23:10:10

which is the syntax/semantics division, ->> can manipulate objects of syntax (what is read), not semantics (evaluation being the determination of meaning)

andy.fingerhut23:10:13

I mean, one could write their own variant of ->> that at run time determined whether each of the expressions returned a function or not, but if you tried to do that, the expressions would have to be evaluated, and they would be missing a parameter, and attempt to call the wrong arity.

andy.fingerhut23:10:54

Haskell has syntactic currying of function calls always, everywhere. Clojure doesn't. Not sure if that is what you might be thinking of.

jumpnbrownweasel23:10:05

This is just a workaround, but perhaps a practical one:

(let [f (comp clojure.string/upper-case name)]
          (->> :foo f))
;; => "FOO"

hiredman23:10:40

and a good illustration of the syntax vs. semantics difference

hiredman23:10:25

you changed the syntax so ->> is passed the literal symbol f, instead of a list of symbols, even though those things have the same meaning

andy.fingerhut23:10:27

Yeah, which is equivalent to the version of that with (->> :foo (f)). The version you wrote can only dispense with the parens around f because ->> and -> have a special case for expression that return false for seq?

jumpnbrownweasel23:10:38

Yeah, I guess some always add the parens (f) as a matter of style, to avoid that special case.

ag23:10:05

so what is happening to comp within a thread macro, why for example this works:

(->> :foo clojure.string/upper-case eval)
but this one doesn’t
(->> :foo (comp clojure.string/upper-case name) eval)

ag23:10:50

in both cases the second thing is a function, but why do they work differently?

jumpnbrownweasel23:10:21

It really is syntactic. In the second case it inserts :foo before the closing paren ... name :foo)