Fork me on GitHub
#clojurescript
<
2019-08-21
>
marciol02:08:11

Hi all. I’m studying the internals of Clojure and ClojureScript and noticed that all persistent data structures in ClojureScript were written in ClojureScript itself, while in Clojure they were written in Java. I was thinking that it turn more suitable to compile/transpile Clojure using ClojureScript. Am I correct?

jaihindhreddy09:08:07

I believe this is mostly because deftype and defprotocol were added later to Clojure whereas they were available right from the beginning in Clojurescript. Those are necessary to write such low-level constructs.

marciol09:08:23

Interesting. Seems that it is the case.

Silenced Ego02:08:39

Why is loop/recur missing from the cljs cheatsheet: https://cljs.info/cheatsheet/

kah0ona10:08:31

quick CI question. I have a bog-standard figwheel-main based project, and I basically want to run my unit tests using lein fig:test-headless in circleCI. What environment would be appropriate to run the tests in? Node? The unit tests are just testing pure functions

kah0ona10:08:53

or do i need to provision each build with a complete chrome headless browser

Lone Ranger12:08:34

@kah0ona I would go with node personally for speed, if you're doing something custom. However since you're using figwheel, did you check out the figwheel testing apparatus? https://figwheel.org/docs/testing.html

kah0ona13:08:59

yeah I did

kah0ona13:08:15

So i have this test runner function, and lein fig:test runs correctly, but it opens a browser window

kah0ona13:08:21

I don’t have that available in circleCI

kah0ona13:08:33

it points to :launch-js directive

kah0ona13:08:05

but, the Chrome thing doesn’t seem to do anything, and i’m not sure how to use Node for this. I mean, do i still need some host page? Or can i just invoke the generated .js file?

kah0ona13:08:06

the latter crashes saying it can’t find document (which makes sense)

kah0ona13:08:38

so i think it needs to be bootstrapped differently somehow

kah0ona13:08:44

i probably should abandon this approach, and use something like https://github.com/Olical/cljs-test-runner

kah0ona13:08:40

lol, i got that working in literally under 3 minutes

😮 4
kah0ona13:08:49

will go for that

Lone Ranger16:08:58

So is there a preferred job board for clojurescript jobs these days?

Lone Ranger16:08:17

or just all the usual place but filter for cljs

kah0ona17:08:58

Hi friends: what would be the way to get the cljs equivalent of this JS: import ptBR from 'date-fns/locale/pt-BR'; registerLocale("pt-BR", ptBR);

kah0ona17:08:12

i have dateFns required through the cljsjs package

kah0ona17:08:53

the more i use clojure(script) almost exclusively, the more i realize i don’t know much about modern javascript 😄

kah0ona17:08:22

i verified from the repl that js/registerLocale is available, and js/dateFns as well

kah0ona17:08:47

or could it be that this cljsjs package doesn’t provide the .locale js module ?

funkrider17:08:29

I am interested in seeing what the clojurecsript compiler is actually doing by stepping through a simple compilation - maybe the hello-world example in the Quick Start, but I am a bit confused how to pass those args into intelliJ and make it step through. Would anybody be able to guide me?

dnolen18:08:49

there's really no way to do that with the QuickStart

dnolen18:08:01

and there's nothing you can do in IntelliJ w/ the QuickStart either

dnolen18:08:48

doing stuff with the compiler isn't hard - but if you're just getting started w/ Clojure(Script) then I would wait a bit

dnolen18:08:35

if you're feeling adventurous you can try some stuff here https://swannodette.github.io/2015/07/29/clojurescript-17

funkrider19:08:55

hey @dnolen im not new to clojurescript and have been using it for a year and a half or so. I am actually interested in hacking the compiler to see if i can get it to emit Dart rather than javascript. I watched the Gellar youtube and worked through the hello-cljs example that you have on gitHub. I understand the relationship between source, the reader, creating an AST and using emit to render JavaScript. I seem to be a bit stuck on where to even start altering the compiler so emit spits Dart rather than JS. I don't even know if it would be a reasonable thing to do maybe maybe not?

marciol19:08:50

I’m also doing the same, I watched the Gellar presentation as well.

marciol19:08:14

I think that a good start would be to emit Dart AST, I am planning to do it.

funkrider19:08:01

hey @U28A9C90Q - the Dart AST is binary and I don't know if you could actually do that from a Java thread? Did you see: https://thosakwe.com/aot-compilation-and-other-dart-hackery/ or https://github.com/thosakwe/bullseye ?

funkrider19:08:45

It might be possible to use something like Protocol Buffers to pass data from Java to a Dart thread with the AST in it - however that would seem harder than just emiting a text file with the dart source

marciol19:08:58

@ian.davies I was thinking in reverse engineer the frontend dart compiler: https://github.com/dart-lang/sdk/tree/master/pkg/front_end

marciol19:08:02

Another way is to convert the frontend to java using https://github.com/google/dart2java

funkrider19:08:46

oh I didn't know about the dart2Java

funkrider19:08:55

would that get you reliable Dart Kernel files even if it worked?

marciol19:08:32

Don’t know yet, I intend to make some experiments this week

marciol19:08:03

I know other people that are interested in contribute as well

funkrider19:08:05

cool let me know how you make out. I don't suppose you have any insight into the clojurescript compiler?

marciol19:08:17

No, I’m learning how it works, but seems pretty straightforward

funkrider19:08:22

The thing I am having difficulty wrapping my head around is how to separate out the requirement that clojurescript has on using the google closure compiler and all its helpers/classes

marciol19:08:29

I heard somewhere that clojurescript compiler doesn’t depend on javascript at all

marciol19:08:25

And even the persistent data structures that are written in Java or C# in Clojure and ClojureCLR respectively, are written in Clojure itself at ClojureScript

marciol19:08:10

So, I think that once one get the emitter working, you can run Clojure on DartVM

marciol19:08:38

But it is a newbie assumption

funkrider19:08:06

Yeah I don't see any hard coded js in the compiler source

funkrider19:08:21

But there is a cljs.core file that defines all the main clojure functions, interfaces etc. that would have to be mapped to Dart

funkrider19:08:41

For example you can't do function overloading in Dart

funkrider19:08:50

and IFn is pretty central

marciol19:08:09

Hmm, makes sense

marciol19:08:35

Not be able to do function overload is a stopper

funkrider21:08:44

Could just write it as a macro and use an if statement within the main function that later invoked the right dart target. Dart also has a kind of catch all no such method function you can use.

marciol21:08:33

Yep, I think that macro approach is better than relying on catch all, that resembles ruby method_missing

kah0ona19:08:56

I ended up using npm, create a webpack bundle, and importing that through :foreign-libs.

kah0ona19:08:22

but it works now 🙂

dnolen20:08:06

@ian.davies it's worth considering just generating Dart source, Dart can hot reload and far as I know they aren't interested in a portable bytecode thing or anything

dnolen20:08:15

also this conversation is probably better in #cljs-dev

dnolen20:08:36

FWIW I don't think there's much value in going through other tools since in the end you don't care that much about the thing you generate in our case

dnolen20:08:57

people explored generating JS AST etc. w/ ClojureScript but it's just a lot of complexity minimal value add

dnolen20:08:08

it also just made everything slower

dnolen20:08:30

(generation)

marciol21:08:52

Great tip @dnolen I was thinking about this possibility after reading that the Dart Kernel IR could change anytime

funkrider21:08:42

Thanks @dnolen. I didn’t know about the dev channel. I’ll check it out.