clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Evan Haveman 2021-05-15T02:01:06.476100Z

are there any good guides on starting a simple clojurescript project that doesn’t need the browser (eg a library of functions). i know i can use node. but i cant seem figure out what my deps.edn should look like, what the command line is to open a repl and play with my code, and what the command line is to run my tests.

raspasov 2021-05-15T08:03:57.476800Z

clj -Sdeps ‘{:deps {org.clojure/clojurescript {:mvn/version “RELEASE”}}}’ -M -m cljs.repl.node

raspasov 2021-05-15T08:04:58.477Z

… assuming you have: src/foo/core.cljs You should be able to successfully run: (require ’foo.core) (in-ns ’foo.core)

raspasov 2021-05-15T08:05:09.477200Z

… from the REPL

raspasov 2021-05-15T08:11:17.477400Z

https://github.com/raspasov/cljs-101

λmmij 2021-05-15T14:56:57.479400Z

This does not work for me.

Evan Haveman 2021-05-15T15:26:46.482300Z

thank you @raspasov that worked. turns out clj -M -m cljs.main --repl --repl-env node also works if i then manually require in my code when it starts. the --compile option doesnt seem to work. but i can live without that so now i have that as my command line to start the repl my deps.edn is {_:deps_ {org.clojure/clojurescript {_:mvn/version_ "1.10.844"}} _:paths_ ["src" "test"]} and i can require in my test package and run my tests inside the repl. progress!

👍 1
Evan Haveman 2021-05-15T02:01:31.476200Z

clj -M --main cljs.main --compile foo.core --repl works fine to open a repl connected to a browser and im able to run my code but when i try `clj -M --main cljs.main --repl-env node --compile foo.core --repl` the repl loads (without the browser) but i can’t run my code. `Execution error (ReferenceError) at (<cljs repl>:1). foo is not defined`

Ale 2021-05-15T15:00:43.481400Z

Hello, beginner question: how do I import SQLite from 'sqlite-react-native-storage' in cljs? I tried (require '[sqlite-react-native-storage :refer [SQLite]]) but it fails with TypeError: undefined is not an object (evaluating 'dondai.core.node$module$react_native_sqlite_storage.SQLite')

raspasov 2021-05-15T15:12:05.481600Z

I see a space in “: refer”. There should be no space.

Ale 2021-05-15T15:20:35.481800Z

sorry. just a typo here on slack. The es5 way to require the library would be just require('react-native-sqlite-storage'), but for some reason doing that returns nil on my repl.

Ale 2021-05-15T15:23:33.482100Z

I mean, doing it the cljs way - I tried both (require '[react-native-sqlite-storage :as foo]) and (js/require "react-native-sqlite-storage"). I checked the library is working correctly by requiring it from krell_repl.js from the build output directory (`target/`)

thheller 2021-05-15T16:06:42.482500Z

in react-native things cannot be required dynamically as metro needs to fill them in

thheller 2021-05-15T16:06:58.482700Z

so you can only use it if one of your source file requires it already and you reload that app

Jakub Holý 2021-05-15T16:48:35.483Z

Hi folks! Any good React intro for a would-be Reframe/Fulceo/etc. user, one that explains all the important things without wasting too much time on things irrelevant for us? The best I found after hours of digging is https://dzone.com/articles/fun-with-react-a-quick-overview and a few pages from React's own tutorial (linked to from https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/index.html#_prerequisites) 🙏

Ale 2021-05-15T16:55:44.483400Z

I see! that did the trick, thanks ^^

Ale 2021-05-15T16:57:14.483600Z

I initially tried requiring from a source file but failed - but after cleaning the target directory up and restarting it worked

dpsutton 2021-05-15T17:15:47.484500Z

does anyone happen to have a figwheel-main example app using the bundle target and react from npm? would love a simple hello world, or perhaps the flappy bird repo updated for bundle

athomasoriginal 2021-05-16T19:03:15.021700Z

You can try https://github.com/athomasoriginal/create-reagent-app as a simple hello world. All you should need to do is add React to the package.json, run npm install and then require it in and everything else should be setup.

athomasoriginal 2021-05-16T19:03:58.022800Z

I will actually update the template to default to this later this week.

peterdee 2021-05-15T17:52:40.487700Z

There must be something about clojure reader conditionals that I’m not understanding, maybe regarding their use in macros. I have the following code in a macro; the java part of it, java.lang.Exception, is getting into my .js (compiled through shadow-cljs): (try ~@body #?(:clj (catch Exception e# {:error (.getMessage e#) :pstate ~pstate}) :cljs (catch js/Error e# {:error (str e#) :pstate ~pstate}))))

thheller 2021-05-15T17:53:57.488400Z

@peterd reader conditionals are resolved at read-time, you cannot use them to emit conditional code in macros. the typical check is (if (:ns &amp;env) :cljs :clj)

peterdee 2021-05-15T17:55:42.488800Z

Oh, I see. Thanks!

peterdee 2021-05-15T17:58:50.489Z

Or, maybe I don’t see. Where do I put this ‘if’ ?

thheller 2021-05-15T18:03:12.489200Z

(try ~@body
     ~(if (:ns &amp;env)
        `(catch js/Error e# {:error (str e#) :pstate ~pstate})
        `(catch Exception e# {:error (.getMessage e#) :pstate ~pstate})
        ))

thheller 2021-05-15T18:03:14.489400Z

something like that

peterdee 2021-05-15T18:05:02.489600Z

Thank you!

Jakub Holý 2021-05-15T18:45:59.489800Z

There is a library for helping with that, can't remember the name. Maybe @adam678 know?

peterdee 2021-05-15T18:49:21.490Z

That would be good to see.

thheller 2021-05-15T18:52:05.490300Z

macrovich

peterdee 2021-05-15T18:53:28.491400Z

What reason might a file of macros not find something like printf? I get Use of undeclared Var cljs.core/printf

peterdee 2021-05-15T18:55:09.491500Z

Ah, I see. And it uses a namespace “being.john” 😄

Helins 2021-05-15T18:55:33.491700Z

Understand reader conditionals is a bit tricky in that regard. Using them in a macro is only useful when you use self hosted CLJS. What Thomas suggests is using a little trick, knowing that when a macro expands code for CLJS, its &amp;env value contains :ns.

peterdee 2021-05-15T18:56:15.491900Z

Agreed. Tricky.

thheller 2021-05-15T18:56:43.492300Z

cljs doesn't have a printf

Helins 2021-05-15T18:56:46.492400Z

So yeah, Macrovitch is a lib that leverage that, and this one as well but a bit differently : https://github.com/helins/medium.cljc (it tries to distinguish even between CLJS for dev and CLJS for release)

alexmiller 2021-05-15T18:58:07.492700Z

the key shift in thinking is that macros are about WRITING code so you need conditional write, not conditional read

👍 2
peterdee 2021-05-15T19:02:25.495400Z

My mistake. Googling I found it defined in the clojure/clojurescript repository. But didn’t notice that I was looking at a view from 2013!

peterdee 2021-05-15T19:04:51.495600Z

Yes, and the &env trick is about the time of the evaluation of the conditional to perform the write, I suppose.

peterdee 2021-05-15T19:08:28.495900Z

@adam678 your library gets right to the point. Thanks!

🙏 1
paulbutcher 2021-05-15T21:14:33.000900Z

What should I be looking at for space-efficient Clojurescript serialisation? I’m currently using edn, but it’s creating files which are rather too big for comfort. I’m aware of Transit, but the documentation suggests that it’s not ideal for data which needs to be stored durably (which I do need). Nippy doesn’t support Clojurescript. Is there anything else that I should be looking at?

dpsutton 2021-05-15T21:16:28.002Z

What size are you talking about? And can you use a database?

paulbutcher 2021-05-15T22:42:25.004Z

The data is of the order of 10s to 100s of megabytes when serialised (much less when in RAM).

paulbutcher 2021-05-15T22:43:02.004200Z

I could use a database, but right now the data is just files on an S3 bucket and I would rather keep it that way unless there’s a strong reason to introduce a database.

dpsutton 2021-05-15T23:02:37.004400Z

i'd say at the tune of 100s of megabytes you are firmly in database territory

dpsutton 2021-05-15T23:03:10.004600Z

at that point you really need random access to the data, or perhaps if you can partition it into multiple files and basically index it yourself

p-himik 2021-05-15T23:16:48.007200Z

It should be fine to use transit as long as you use the very same library version and the same settings to both read and write the same file. As soon as the version changes or some config changes, all bets are off.

paulbutcher 2021-05-15T23:18:03.009Z

I see why you are thinking database, but these are "all or nothing" files (they're data logs from racecar telemetry, as it happens). The Clojurescript is mainly just passing them along to Vega for visualisation.

paulbutcher 2021-05-15T23:18:36.009900Z

Thanks @p-himik. It's the "all bets are off" bit that's worrying me.

phronmophobic 2021-05-15T23:18:56.010300Z

another option is to just use edn and use something like gzip on the result

paulbutcher 2021-05-15T23:19:51.011700Z

@smith.adriane: that's where I suspect I may be headed. But I thought I'd check to see if there was a better option first 👍