Native, fast starting Clojure interpreter for scripting
EPL-1.0 License
Bot releases are visible (Hide)
Java interop is now done via reflection. This means we don't have to write function wrappers to fake interop anymore.
The following Java classes are supported.
ArithmeticException
AssertionError
Boolean
Class
Double
Exception
clojure.lang.ExceptionInfo
Integer
java.io.File
java.util.regex.Pattern
String
System
Thread
We can now have (Double/parseDouble "2.0")
, Integer/MAX_VALUE
or (.write (io/writer "foo"))
by just adding the class entries to reflection.json
and the :classes
option to sci.
The import
macro now works: (import '[clojure.lang.ExceptionInfo])
.
$ ./bb "(eval '(+ 1 2 3))"
6
See #107.
for
https://github.com/borkdude/sci/issues/140
doall
, dorun
and namespace
(https://github.com/borkdude/sci/issues/130, https://github.com/borkdude/sci/issues/139)Babashka now supports reader conditionals.
Upgrade sci which now comes with support for try/catch/finally
+ defmacro
.
read-line
clojure.java.io
functionsloop
macrofor
and doseq
macrosrequire
Integer/parseInt
clojure.tools.cli
:(require '[clojure.tools.cli :refer [parse-opts]])
(def cli-options
;; An option with a required argument
[["-p" "--port PORT" "Port number"
:default 80
:parse-fn #(Integer/parseInt %)
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
["-h" "--help"]])
(:options (parse-opts *command-line-args* cli-options))
$ bb script.clj
{:port 80}
$ bb script.clj -h
{:port 80, :help true}
sig/pipe-signal-received?
:$ bb '((fn [x] (println x) (when (not (sig/pipe-signal-received?)) (recur (inc x)))) 0)' | head -n2
1
2
sci #54: support recur
#60: fix shebang /usr/bin/env
support under linux (thanks @plexus)
#48: be able to spawn and kill processes. See docs. Also see below example at #50.
#49: add Thread/sleep
#50: add net/wait-for-it
, a function that does the same as the famous bash script:
$ bb '
(def ws (conch/proc "python" "-m" "SimpleHTTPServer" "1777"))
(net/wait-for-it "localhost" 1777) (conch/destroy ws)'
Add future
, atom
, reset!
and swap!
Support comment
and #_
(uneval)
Support for *command-line-args*
and *in*
when running a socket REPL
-h
as alias for --help
-i
lazy. This allows expressions like:$ yes | bb -io '(take 2 *in*)'
y
y
which would be the equivalent to:
$ yes | head -n2
-I
and -O
options. These behave equivalently to -i
and -o
, but for EDN values:$ bb -O '(repeat "dude")' | bb --stream '(str *in* "rino")' | bb -I '(take 3 *in*)'
("duderino" "duderino" "duderino")
n
results using head
:$ ./bb -o '(range)' |
./bb --stream '(* *in* *in*)' |
head -n10
0
1
4
9
16
25
36
49
64
81
After printing the last number, all the processes exit.
Upgrade to sci 0.0.9 which outputs location info in case of an error.
$ ls | bb -i '(count *in)'
Could not resolve symbol: *in [at line 1, column 8]
$ ls | bb -i '(count *in*)'
15
Upgrade to sci v0.0.8. See https://github.com/borkdude/sci/releases/tag/v0.0.8.