nbb

Aron 2022-08-10T12:10:27.424169Z

Can I somehow bundle a clojure dependency with nbb/package.json?

Aron 2022-08-10T12:11:31.769819Z

what would have to be installed for it to work. Is it better to just avoid it? Basically, I like test.check and would like to use it but seems like too much complication, not possible just to do an npm install on the other side and have it working

borkdude 2022-08-10T12:12:17.847689Z

I don't think test.check currently works with nbb... does it? I'd be surprised if it did

Aron 2022-08-10T12:25:58.104539Z

haven't got that far 😄

Aron 2022-08-10T12:26:16.648559Z

I just saw that you can load clojure deps from classpath

borkdude 2022-08-10T12:26:44.802699Z

yes, but not all .cljs code will work with nbb, unfortunately

Aron 2022-08-10T12:26:48.297159Z

need something to do property based testing with

Aron 2022-08-10T12:26:57.900489Z

but then probably better if I use a js module

borkdude 2022-08-10T12:27:02.066379Z

babashka does support test.check

Aron 2022-08-10T16:15:49.970279Z

sounds good, but I am not sure if I can create a simple, self-contained package with babashka that someone who is used to the node ecosystem (npm install level of involvement:))

borkdude 2022-08-10T16:16:27.583469Z

yeah, I guess you could use an existing npm package for this then

borkdude 2022-08-10T16:17:28.909699Z

you could also create a self-contained executable for a babashka program: https://github.com/babashka/babashka/wiki/Self-contained-executable but this means you'd have to create one for every OS/arch you'd like to support

borkdude 2022-08-10T16:17:45.750229Z

having people install babashka and then letting them run your script is much easier

Aron 2022-08-10T16:19:29.187589Z

yeah, there are definitely use cases where I would take that route, but this would be some tech test for interview

Aron 2022-08-10T16:19:49.016679Z

and they didn't define the language, so I am just trying to surprise them a little

Aron 2022-08-19T08:51:58.911089Z

finally finished it, but as a beginner, I would really appreciate some reviews on it, if anyone has the time and inclination https://github.com/ashnur/nimble-tt

🎉 1
Ed 2022-08-19T11:40:26.137439Z

in valid-rank? you've written (and (< 1 rank) (> 15 rank)) which you could write as (< 1 rank 15) ... but shouldn't that be (< 0 rank 15)? I would have thought that 1 was a valid card rank to have.... ah ... no ... sorry ... just spotted that you're turning 1 into 14 in hand-result forcing aces to be high ... does that mean you can't have a flush of 1 2 3 4 5?

Ed 2022-08-19T11:43:39.058169Z

Also, I would have expected the namespace to be main rather than src.main

Ed 2022-08-19T11:45:58.548599Z

(mapv (partial vector) ranks suits) is the same as (mapv vector ranks suits)

Ed 2022-08-19T11:49:56.380959Z

(seq (filter (complement valid-rank?) ranks)) is can be shortened to (seq (remove valid-rank?) ranks) but I think it would be clearer to write (every? valid-rank? ranks)

Aron 2022-08-19T15:43:32.054789Z

Ed, that's a good catch about the flush

Aron 2022-08-19T15:43:46.933269Z

and I never understand the namespaces

Aron 2022-08-19T15:43:55.935459Z

literally any time I try anything, it's wrong

Aron 2022-08-19T15:44:42.900289Z

I can't even find any documentation on it, like different dir structures used differently, and what is the appropriate namespacing for them

Aron 2022-08-19T15:49:42.082059Z

every? valid-rank? ranks is great suggestion too, not sure how i missed it

Aron 2022-08-19T16:16:00.996519Z

err... not flush, straight, but I got your meaning

Ed 2022-08-19T16:47:45.647829Z

The file layout convention comes from the Java world where it's common to have a src directory with all your application code in and a test directory with your tests in. Often in Clojure land you'd describe the directory layout and dependencies for your project in a deps.edn file (https://clojure.org/reference/deps_and_cli#_paths) The relationship between the namespace and the filename is generally a directory for each of the parts of the namespace when separated with a . except the last one, which will be a file. So (ns foo.bar.baz ,,,) will be in src/foo/bar/baz.clj and you'd probably put tests for that ns in (ns foo.bar.baz-test ,,,) / test/foo/bar/baz_test.clj - and there we find the next wrinkle. For namespaces that have a - in them we need to replace it with a _ in the filename. This is because of a restriction in the jvm, and ClojureScript has followed the same convention to stay compatible. There's some more info here: https://www.clojure.org/guides/learn/namespaces#_loading ... does that make sense?

Ed 2022-08-19T16:48:28.024799Z

> err... not flush, straight, but I got your meaning yeah ... sorry - I'm not so good at poker 😉

Aron 2022-08-19T16:57:31.683819Z

Yeah, it is an easy fix in clojure, I just added an (or (= ranks [2 3 4 5 14])), since it's ordered, should be fine

Aron 2022-08-19T16:57:48.625599Z

the part I don't get in namespaces is exactly what you also don't mention btw 😄

Aron 2022-08-19T16:58:01.539289Z

if I have src and test, how do I refer between them?

Aron 2022-08-19T16:58:34.897219Z

often it appears to me that whole directories are created for no reason at all

Ed 2022-08-19T19:53:03.077849Z

I think I'm general the src directory is used to keep the code you're intending to ship to production and the test directory is for your tests that you probably won't include in the deployable artifacts. In development they both paths should be on the list of places that would get searched for namespaces.

👍🏻 1
Aron 2022-08-19T20:00:01.450659Z

thanks, that's helpful hint

borkdude 2022-08-10T16:20:04.345849Z

:)

Aron 2022-08-10T16:20:47.911679Z

it's exactly the kind of stuff that's complicated in js but in clojure it will be very short

borkdude 2022-08-10T16:22:23.711969Z

@ashnur I found this one: https://github.com/leebyron/testcheck-js

Aron 2022-08-10T16:24:25.887699Z

there are a couple ones in js https://www.npmjs.com/package/fast-check

Aron 2022-08-10T16:24:49.278599Z

just wanted to be sure that test.check is not possible or too difficult

borkdude 2022-08-10T16:50:43.861429Z

I haven't actually tried to run from source, but I'd expect there to be something non-compatible

borkdude 2022-08-10T16:52:47.758099Z

$ npx nbb --classpath src/main/clojure -e "(require '[clojure.test.check])"
----- Error --------------------------------------
Message:  Could not find namespace: goog.math.Long
Hmm ok, that's the first issue

Aron 2022-08-10T16:56:34.128669Z

😄

2022-08-10T21:44:41.013449Z

Writing a build script that fetches some json, formats it to edn, then wraps it in a (def some-data ...edn-data... ). Trying to think of a way to format it. Maybe call pprint and leverage quoting so it treats the outer (def some-data ...) as a list?

teodorlu 2022-08-11T16:35:08.677859Z

> Maybe call pprint and leverage quoting so it treats the outer (def some-data ...) as a list? That's what I'd do. Though I think I'd quote the whole EDN thing as well, producing (def some-data (quote literal-edn)) This will fail when trying to read :items:

user=> (clojure.pprint/pprint (list 'def 'some-data {:point {:x 1 :y 2} :name "Harold" :items (range 20)}))
(def
 some-data
 {:point {:x 1, :y 2},
  :name "Harold",
  :items (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)})
This should work fine:
user=> (clojure.pprint/pprint (list 'def 'some-data (list 'quote {:point {:x 1 :y 2} :name "Harold" :items (range 20)})))
(def
 some-data
 '{:point {:x 1, :y 2},
   :name "Harold",
   :items (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)})

teodorlu 2022-08-11T16:36:03.828289Z

if you can survive

(def
 some-data
😄

2022-08-11T16:38:23.711599Z

Landed on the following:

(pprint-str `(def ~'cloud-services ~cloud-services-json))
then can use the replace function to clean that up

👍 1