This commit is contained in:
Michiel Borkent 2020-04-24 11:08:28 +02:00
parent 9b7bf0c345
commit ad5b08c76a

View file

@ -351,7 +351,7 @@ The namespace `babashka.curl` is a tiny wrapper around curl. It's aliased as
`curl` in the user namespace. See `curl` in the user namespace. See
[babashka.curl](https://github.com/borkdude/babashka.curl). [babashka.curl](https://github.com/borkdude/babashka.curl).
## Running a file ## Running a script
Scripts may be executed from a file using `-f` or `--file`: Scripts may be executed from a file using `-f` or `--file`:
@ -386,8 +386,6 @@ Using `bb` with a shebang also works:
(println "Usage: <url> <file>") (println "Usage: <url> <file>")
(System/exit 1)) (System/exit 1))
(write-html file (get-url url))) (write-html file (get-url url)))
(System/exit 0)
``` ```
``` shellsession ``` shellsession
@ -415,6 +413,42 @@ $ cat script.clj
("hello" "1" "2" "3") ("hello" "1" "2" "3")
``` ```
## Style
A note on style. Babashka recommends the following:
- Only use `*input*` and aliases without require in bash one-liners.
Do this:
```
$ ls | bb -i '(-> *input* first (str/includes? "m"))'
true
```
But not this:
script.clj:
```
(-> *input* first (str/includes? "m"))
```
Rather do this:
script.clj:
```
(ns script
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(-> (io/reader *in*) line-seq first (str/includes? "m"))
```
Some reasons for this:
- Linters like clj-kondo work better with code that uses namespace forms, explicit requires, and known Clojure constructs
- Editor tooling works better with namespace forms (sorting requires, etc).
- Writing compatible code gives you the option to run the same script with `clojure`
## [Running a REPL](doc/repl.md) ## [Running a REPL](doc/repl.md)
Babashka offers a REPL, a socket REPL and an nREPL server. Look Babashka offers a REPL, a socket REPL and an nREPL server. Look