If anyone is using Cursive, how do you connect to bb nrepl or socket repl?
@roklenarcic https://book.babashka.org/#repl and then ctrl-f for Cursive
(sorry, that part of the docs was not included, I added it back now)
thanks
is there any type of "lein" tool for BB? Dependency management / configuration / environment management etc
@kevin.van.rooijen Not yet. We're brainstorming about this here: https://github.com/borkdude/babashka/issues/473
For dependency management you currently use clojure
and set the printed classpath using the -Spath
option to the BABASHKA_CLASSPATH
environment variable or you pass the string directly to the --classpath
option.
so typically: bb --classpath $(clojure -Spath) -m foo.main
Ah cool. I'll read up on that
Also, unrelated; Any plans / ideas / is it even possible for bytecode compiled BB? Basically to improve require speeds, similar to pyc files in python
Or elc files in Elisp
No plans yet, but it's a cool idea.
Do you think that's possible? I haven't looked at the implementation of sci
But that would be amazing
Also for obfuscation purposes
I think the output from the analyzer namespace could be made printable so the interpreter could load that instead of parsing and analyzing the source from scratch. But this would need benchmarking to see if loading the analyzed output is actually faster (it should be but you never know unless you measure).
If you want to know more about sci internals, I recommend watching my talk on it: https://youtu.be/pgNp4Lk3gf0
Will do
@kevin.van.rooijen In this area, running the uberscript + carve over the namespaces will likely also help. https://book.babashka.org/#_uberscript
Yeah that's a nice flag
Is there any way to get the classpaths in BB? There is a cp-state atom that gets modified when you run add-classpath
but it's not accessible AFAIK https://github.com/borkdude/babashka/blob/67c33b227009b47131fb145bed42cf4742aa4586/src/babashka/main.clj#L356
In clj you would use clojure.java.classpath
I think, but that doesn't work in bb
My goal is to get all clj files that are available to be required
We could make this available under a system property, but a function in babashka.classpath could also work
I can make a PR for that
let's first decide on the solution then :)
I think a function is babashka.classpath would be nice
There are already these: https://book.babashka.org/#_system_properties But maybe a function is better, since the value can change. Right.
It's also a "logical" place to look, since the namespace is already called classpath
get-classpath
? or just classpath
?
Multiple directories is still a single classpath, right?
So it wouldn't be classpaths
?
yes, I think it should return the classpath as is, so foo:bar:baz
, that's one classpath
Ok, I'd prefer classpath
myself
ok, go ahead then
There aren't really any side effects, other than reading an atom
a seq of strings or vector?
Or just the raw string with colon separator?
the raw string
๐
we could add a function parse
or something, but I would do that as a separate function and only if there is a good reason to add it. generally it's just (split ... (re-pattern file-separator))
for now let's only do classpath
Works for me
#!/usr/bin/env bb
(require '[babashka.classpath :refer [add-classpath]]
'[clojure.java.shell :refer [sh]]
'[org.httpkit.server :as server])
(defn app [req]
{:status 200
:headers {"Content-Type" "text/html"}
:body "hello HTTP!"})
(defonce server (atom nil))
(defn stop-server []
(when-not (nil? @server)
;; graceful shutdown: wait 100ms for existing requests to be finished
;; :timeout is optional, when no timeout, stop immediately
(@server :timeout 100)
(reset! server nil)))
(defn -main [& args]
;; The #' is useful when you want to hot-reload code
;; You may want to take a look: <https://github.com/clojure/tools.namespace>
;; and <https://http-kit.github.io/migration.html#reload>
(reset! server (server/run-server #'app {:port 8080})))
(-main)
Why this is not running the web-server?it's returning me
#object[clojure.lang.AFunction$1 0x4d572c3e "clojure.lang.AFunction$1@7fa00b1a1648"]
I think because the main thread isn't blocking
It starts the server on a new thread and then exits the main thread, exiting the program
yes
If you do this
(defn -main [& args]
;; The #' is useful when you want to hot-reload code
;; You may want to take a look: <https://github.com/clojure/tools.namespace>
;; and <https://http-kit.github.io/migration.html#reload>
(reset! server (server/run-server #'app {:port 8080}))
@(promise))
(-main)
the promise will block (since it canโt be derefโed)
โฏ http :8080
HTTP/1.1 200 OK
Content-Length: 11
Content-Type: text/html
Date: Fri, 04 Dec 2020 20:43:45 GMT
Server: http-kit
hello HTTP!
aw thanks thanks
๐
Youโre most welcome ๐
yey thanks!
Neat, just tried interpolating a whole form into my $
usage (from babashka.process), and it worked well. I was writing something like this:
(let [arg (str "/home" "/nate")]
($ ls ~arg))
but now I write this:
($ ls ~(str "/home" "/nate"))