From 36cf1a8d7076447fea66a14b3739516d89ee1519 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 7 Nov 2020 20:42:48 +0100 Subject: [PATCH] README [skip ci] --- doc/io-flags.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/io-flags.md b/doc/io-flags.md index 9e8b2706..e1b7b1ce 100644 --- a/doc/io-flags.md +++ b/doc/io-flags.md @@ -6,7 +6,8 @@ which binds `*input*` to a lazy seq of lines of text. If you want to read multiple EDN values, use the `-I` flag. The `-o` option prints the result as lines of text. The `-O` option prints the result as lines of EDN values. -> **Note:** `*input*` is only available in the `user` namespace, on other namespaces use `*in*`. +> **Note:** `*input*` is only available in the `user` namespace, designed for +> one-liners. For writing scripts, see [scripts](#scripts). The following table illustrates the combination of options for commands of the form @@ -28,11 +29,13 @@ $ echo '{:a 1} {:a 2}' | bb --stream '*input*' {:a 2} ``` -When writing Clojure scripts that should be fully portable with the JVM, it is -not recommended to use in- and output flags and `*input*` since those are not -available in standard Clojure. Here is how you can rewrite: +## Scripts -## EDN input +When writing scripts instead of one-liners on the command line, it is not +recommended to use `*input*`. Here is how you can rewrite to standard Clojure +code. + +### EDN input Reading a single EDN value from stdin: @@ -54,7 +57,7 @@ Reading multiple EDN values from stdin (the `-I` flag): (take-while #(not (identical? ::eof %)) (repeatedly #(edn/read {:eof ::eof} reader)))) ``` -## Text input +### Text input Reading text from stdin can be done with `(slurp *in*)`. To get a lazy seq of lines (the `-i` flag), you can use: @@ -66,6 +69,6 @@ lines (the `-i` flag), you can use: (line-seq (io/reader *in*)) ``` -## Output +### Output To print to stdout, use `println` for text and `prn` for EDN values.