Fork me on GitHub
#babashka
<
2020-12-04
>
roklenarcic14:12:45

If anyone is using Cursive, how do you connect to bb nrepl or socket repl?

borkdude14:12:45

@roklenarcic https://book.babashka.org/#repl and then ctrl-f for Cursive

borkdude14:12:01

(sorry, that part of the docs was not included, I added it back now)

kwrooijen14:12:11

is there any type of "lein" tool for BB? Dependency management / configuration / environment management etc

borkdude15:12:51

@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.

borkdude15:12:45

so typically: bb --classpath $(clojure -Spath) -m foo.main

kwrooijen15:12:49

Ah cool. I'll read up on that

kwrooijen15:12:20

Also, unrelated; Any plans / ideas / is it even possible for bytecode compiled BB? Basically to improve require speeds, similar to pyc files in python

kwrooijen15:12:44

Or elc files in Elisp

borkdude15:12:43

No plans yet, but it's a cool idea.

kwrooijen15:12:00

Do you think that's possible? I haven't looked at the implementation of sci

kwrooijen15:12:04

But that would be amazing

kwrooijen15:12:30

Also for obfuscation purposes

borkdude15:12:28

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

borkdude15:12:27

If you want to know more about sci internals, I recommend watching my talk on it: https://youtu.be/pgNp4Lk3gf0

๐Ÿ‘€ 1
borkdude15:12:29

@kevin.van.rooijen In this area, running the uberscript + carve over the namespaces will likely also help. https://book.babashka.org/#_uberscript

kwrooijen15:12:36

Yeah that's a nice flag

kwrooijen20:12:05

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

kwrooijen20:12:27

My goal is to get all clj files that are available to be required

borkdude20:12:50

We could make this available under a system property, but a function in babashka.classpath could also work

kwrooijen20:12:02

I can make a PR for that

borkdude20:12:17

let's first decide on the solution then :)

kwrooijen20:12:43

I think a function is babashka.classpath would be nice

borkdude20:12:54

There are already these: https://book.babashka.org/#_system_properties But maybe a function is better, since the value can change. Right.

kwrooijen20:12:48

It's also a "logical" place to look, since the namespace is already called classpath

borkdude20:12:58

get-classpath? or just classpath ?

kwrooijen20:12:35

Multiple directories is still a single classpath, right?

kwrooijen20:12:41

So it wouldn't be classpaths ?

borkdude20:12:59

yes, I think it should return the classpath as is, so foo:bar:baz, that's one classpath

kwrooijen20:12:21

Ok, I'd prefer classpath myself

borkdude20:12:30

ok, go ahead then

kwrooijen20:12:39

There aren't really any side effects, other than reading an atom

kwrooijen20:12:52

a seq of strings or vector?

kwrooijen20:12:16

Or just the raw string with colon separator?

borkdude20:12:34

the raw string

borkdude20:12:24

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

borkdude20:12:40

for now let's only do classpath

kwrooijen20:12:40

Works for me

Ian Fernandez20:12:20

#!/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: 
  ;; and 
  (reset! server (server/run-server #'app {:port 8080})))

(-main)
Why this is not running the web-server?

Ian Fernandez20:12:29

it's returning me

Ian Fernandez20:12:41

#object[clojure.lang.AFunction$1 0x4d572c3e "[email protected]"]

kwrooijen20:12:12

I think because the main thread isn't blocking

kwrooijen20:12:27

It starts the server on a new thread and then exits the main thread, exiting the program

dharrigan20:12:49

If you do this

dharrigan20:12:25

(defn -main [& args]
  ;; The #' is useful when you want to hot-reload code
  ;; You may want to take a look: 
  ;; and 
  (reset! server (server/run-server #'app {:port 8080}))
  @(promise))

(-main)

dharrigan20:12:44

the promise will block (since it canโ€™t be derefโ€™ed)

dharrigan20:12:00

โฏ 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!

๐Ÿ‘ 1
Ian Fernandez20:12:15

aw thanks thanks

dharrigan20:12:09

Youโ€™re most welcome ๐Ÿ˜‰

nate22:12:41

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

๐Ÿ˜Ž 3