Can I somehow bundle a clojure dependency with nbb/package.json?
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
I don't think test.check currently works with nbb... does it? I'd be surprised if it did
haven't got that far 😄
I just saw that you can load clojure deps from classpath
yes, but not all .cljs code will work with nbb, unfortunately
need something to do property based testing with
but then probably better if I use a js module
babashka does support test.check
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:))
yeah, I guess you could use an existing npm package for this then
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
having people install babashka and then letting them run your script is much easier
yeah, there are definitely use cases where I would take that route, but this would be some tech test for interview
and they didn't define the language, so I am just trying to surprise them a little
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
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?
Also, I would have expected the namespace to be main rather than src.main
(mapv (partial vector) ranks suits) is the same as (mapv vector ranks suits)
(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)
Ed, that's a good catch about the flush
and I never understand the namespaces
literally any time I try anything, it's wrong
I can't even find any documentation on it, like different dir structures used differently, and what is the appropriate namespacing for them
every? valid-rank? ranks is great suggestion too, not sure how i missed it
err... not flush, straight, but I got your meaning
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?
> err... not flush, straight, but I got your meaning yeah ... sorry - I'm not so good at poker 😉
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
the part I don't get in namespaces is exactly what you also don't mention btw 😄
if I have src and test, how do I refer between them?
often it appears to me that whole directories are created for no reason at all
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.
thanks, that's helpful hint
:)
it's exactly the kind of stuff that's complicated in js but in clojure it will be very short
@ashnur I found this one: https://github.com/leebyron/testcheck-js
there are a couple ones in js https://www.npmjs.com/package/fast-check
just wanted to be sure that test.check is not possible or too difficult
I haven't actually tried to run from source, but I'd expect there to be something non-compatible
$ 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😄
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?
> 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)})if you can survive
(def
some-data
😄Landed on the following:
(pprint-str `(def ~'cloud-services ~cloud-services-json))
then can use the replace function to clean that up