Fork me on GitHub
#nbb
<
2022-08-10
>
Aron12:08:27

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

Aron12:08:31

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

borkdude12:08:17

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

Aron12:08:58

haven't got that far 😄

Aron12:08:16

I just saw that you can load clojure deps from classpath

borkdude12:08:44

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

Aron12:08:48

need something to do property based testing with

Aron12:08:57

but then probably better if I use a js module

borkdude12:08:02

babashka does support test.check

Aron16:08:49

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

borkdude16:08:27

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

borkdude16:08:28

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

borkdude16:08:45

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

Aron16:08:29

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

Aron16:08:49

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

Aron08:08:58

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
Ed11:08:26

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?

Ed11:08:39

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

Ed11:08:58

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

Ed11:08:56

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

Aron15:08:32

Ed, that's a good catch about the flush

Aron15:08:46

and I never understand the namespaces

Aron15:08:55

literally any time I try anything, it's wrong

Aron15:08:42

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

Aron15:08:42

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

Aron16:08:00

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

Ed16:08:45

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?

Ed16:08:28

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

Aron16:08:31

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

Aron16:08:48

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

Aron16:08:01

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

Aron16:08:34

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

Ed19:08:03

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
Aron20:08:01

thanks, that's helpful hint

Aron16:08:47

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

Aron16:08:49

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

borkdude16:08:43

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

borkdude16:08:47

$ 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

jaide21:08:41

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?

teodorlu16:08:08

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

teodorlu16:08:03

if you can survive

(def
 some-data
😄

jaide16:08:23

Landed on the following:

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

👍 1
Aron08:08:58

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