Fork me on GitHub
#babashka
<
2020-04-03
>
briemens08:04:12

H! 👋 I started playing with babashka today and I was wondering how I can use stdin via *input* , but if no input is provided show a usage message. It seems that babashka blocks on *input* when nothing is "piped" into it. Is there a way to detect if input has been provided before reading it or should I think about this in a different way?

borkdude08:04:07

@briemens

$ bb '(pos? (.available System/in))'
false
$ echo true | bb '(pos? (.available System/in))'
true

borkdude09:04:53

I think it would be good if we documented this in the README

briemens09:04:35

Thanks @borkdude! Another question. Should (System/exit 1) end the process? Because that is not the case atm.

borkdude09:04:46

@briemens interesting. normally it should:

$ bb '(loop [] (System/exit 1) (recur))'; echo $?
1

borkdude09:04:45

@briemens can you make a repro where it doesn't work like expected?

briemens09:04:57

yeah, working on a small reproduceable snippet

briemens09:04:40

Sorry! I made a boo-boo 🤐

borkdude09:04:22

often it's also good to check if something works on the JVM / clojure to see if it's an issue with bb or not

rovanion10:04:30

Is there a reason find-ns alsways resolves to a value?

rovanion10:04:40

The reason why I'm asking is because the emacs inf-clojure mode breaks because of this. It attempts to identify which type of REPL it's in by running a series of forms like:

borkdude10:04:49

@rovanion oh, hmm, I think that's a bug

borkdude10:04:37

can you post an issue (and if you want a PR to fix it)?

borkdude10:04:59

the relevant code is in sci.impl.namespaces (.cljc)

rovanion10:04:17

I'll make an issue out of it, we'll see if I can figure out a fix within reasonable company time ;)

borkdude10:04:14

the idea behind that latter function is to re-use existing namespace objects

borkdude10:04:18

@rovanion just create the issue and I'll think some more about it

borkdude10:04:47

> by running a series of forms like: you didn't actually post the forms

rovanion10:04:01

Right, here are the forms.

;;;; Lumo                                                                                                              
;;;; ====                                                                                                              

(defcustom inf-clojure--lumo-repl-form
  "(find-ns 'lumo.repl)"
  "Form to invoke in order to verify that we launched a Lumo REPL."
  :type 'string
  :safe #'stringp
  :package-version '(inf-clojure . "2.0.0"))

;;;; Planck                                                                                                            
;;;; ====                                                                                                              

(defcustom inf-clojure--planck-repl-form
  "(find-ns 'planck.repl)"
  "Form to invoke in order to verify that we launched a Planck REPL."
  :type 'string
  :safe #'stringp
  :package-version '(inf-clojure . "2.0.0"))

;;;; Joker                                                                                                             
;;;; ====                                                                                                              

(defcustom inf-clojure--joker-repl-form
  "(find-ns 'joker.repl)"
  "Form to invoke in order to verify that we launched a Joker REPL."
  :type 'string
  :safe #'stringp
  :package-version '(inf-clojure . "2.2.0"))

borkdude10:04:42

I'll fix that before the next release, thanks for bringing it up

borkdude10:04:55

I hope to do a release this weekend with the new nREPL server

rovanion10:04:27

Below is the test where the forms are used:

(defun inf-clojure--detect-repl-type (proc)
  "Identifies the current REPL type for PROC."
  (when (not inf-clojure--repl-type-lock)
    (let ((inf-clojure--repl-type-lock t))
      (cond
       ((inf-clojure--some-response-p proc inf-clojure--lumo-repl-form) 'lumo)
       ((inf-clojure--some-response-p proc inf-clojure--planck-repl-form) 'planck)
       ((inf-clojure--some-response-p proc inf-clojure--joker-repl-form) 'joker)
       (t 'clojure)))))

rovanion10:04:27

Both those things sound great!

borkdude10:04:56

if you want to preview the new nREPL server support, go to #babashka_circleci_builds and get a binary from the nrepl-server branch.

borkdude10:04:07

you can start it with bb --nrepl-server 1667

borkdude10:04:48

@rovanion I pushed a fix for 325 to master. The binary should appear within a minute or 10 in #babashka_circleci_builds

rovanion12:04:17

@borkdude Can confirm that that build fixes the issue.

borkdude21:04:21

I merged the nREPL server to master now. To try it out, grab any of these binaries and run with ./bb --nrepl-server 1667. Rolling out a release this weekend. [linux - [email protected]]: https://6022-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.79-SNAPSHOT-linux-amd64.zip [macos - [email protected]]: https://6020-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.79-SNAPSHOT-macos-amd64.zip