diff --git a/README.md b/README.md index dc8a0667..348721a2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A Clojure [babushka](https://en.wikipedia.org/wiki/Headscarf) for the grey areas ``` shellsession $ bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install) -$ ls | bb --time -i '(filter #(-> % io/file .isDirectory) *in*)' +$ ls | bb --time -i '(filter #(-> % io/file .isDirectory) )' ("doc" "resources" "sci" "script" "src" "target" "test") bb took 4ms. ``` @@ -57,29 +57,29 @@ Experimental. Breaking changes are expected to happen at this phase. ## Examples ``` shellsession -$ ls | bb -i '*in*' +$ ls | bb -i '' ["LICENSE" "README.md" "bb" "doc" "pom.xml" "project.clj" "reflection.json" "resources" "script" "src" "target" "test"] -$ ls | bb -i '(count *in*)' +$ ls | bb -i '(count )' 12 -$ bb '(vec (dedupe *in*))' <<< '[1 1 1 1 2]' +$ bb '(vec (dedupe ))' <<< '[1 1 1 1 2]' [1 2] -$ bb '(filterv :foo *in*)' <<< '[{:foo 1} {:bar 2}]' +$ bb '(filterv :foo )' <<< '[{:foo 1} {:bar 2}]' [{:foo 1}] -$ bb '(#(+ %1 %2 %3) 1 2 *in*)' <<< 3 +$ bb '(#(+ %1 %2 %3) 1 2 )' <<< 3 6 -$ ls | bb -i '(filterv #(re-find #"reflection" %) *in*)' +$ ls | bb -i '(filterv #(re-find #"reflection" %) )' ["reflection.json"] $ bb '(run! #(shell/sh "touch" (str "/tmp/test/" %)) (range 100))' -$ ls /tmp/test | bb -i '*in*' +$ ls /tmp/test | bb -i '' ["0" "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" ...] -$ bb -O '(repeat "dude")' | bb --stream '(str *in* "rino")' | bb -I '(take 3 *in*)' +$ bb -O '(repeat "dude")' | bb --stream '(str "rino")' | bb -I '(take 3 )' ("duderino" "duderino" "duderino") ``` @@ -136,12 +136,12 @@ Options: --help, -h or -? Print this help text. --version Print the current version of babashka. - -i Bind *in* to a lazy seq of lines from stdin. - -I Bind *in* to a lazy seq of EDN values from stdin. + -i Bind to a lazy seq of lines from stdin. + -I Bind to a lazy seq of EDN values from stdin. -o Write lines to stdout. -O Write EDN values to stdout. --verbose Print entire stacktrace in case of exception. - --stream Stream over lines or EDN values from stdin. Combined with -i or -I *in* becomes a single value per iteration. + --stream Stream over lines or EDN values from stdin. Combined with -i or -I becomes a single value per iteration. -e, --eval Evaluate an expression. -f, --file Evaluate a file. -cp, --classpath Classpath to use. @@ -214,7 +214,7 @@ conditionals](#reader-conditionals) to maintain compatibility with JVM Clojure. Special vars: -- `*in*`: contains the input read from stdin. EDN by default, multiple lines of +- ``: contains the input read from stdin. EDN by default, multiple lines of text with the `-i` option, or multiple EDN values with the `-I` option. - `*command-line-args*`: contain the command line args @@ -330,7 +330,7 @@ export BABASHKA_PRELOADS Note that you can concatenate multiple expressions. Now you can use these functions in babashka: ``` shellsession -$ bb '(-> (foo *in*) bar)' <<< 1 +$ bb '(-> (foo ) bar)' <<< 1 6 ``` @@ -340,7 +340,7 @@ You can also preload an entire file using `load-file`: export BABASHKA_PRELOADS='(load-file "my_awesome_prelude.clj")' ``` -Note that `*in*` is not available in preloads. +Note that `` is not available in preloads. ## Classpath @@ -563,7 +563,7 @@ welcome! ### Delete a list of files returned by a Unix command ``` -find . | grep conflict | bb -i '(doseq [f *in*] (.delete (io/file f)))' +find . | grep conflict | bb -i '(doseq [f ] (.delete (io/file f)))' ``` ### Calculate aggregate size of directory @@ -597,7 +597,7 @@ $ cat /tmp/test.txt 3 Babashka 4 Goodbye -$ < /tmp/test.txt bb -io '(shuffle *in*)' +$ < /tmp/test.txt bb -io '(shuffle )' 3 Babashka 2 Clojure 4 Goodbye @@ -611,7 +611,7 @@ For converting JSON to EDN, see [jet](https://github.com/borkdude/jet). ``` shellsession $ curl -s https://api.github.com/repos/borkdude/babashka/tags | jet --from json --keywordize --to edn | -bb '(-> *in* first :name (subs 1))' +bb '(-> first :name (subs 1))' "0.0.4" ``` @@ -620,8 +620,8 @@ bb '(-> *in* first :name (subs 1))' ``` shellsession $ curl -s https://api.github.com/repos/borkdude/babashka/releases | jet --from json --keywordize | -bb '(-> *in* first :assets)' | -bb '(some #(re-find #".*linux.*" (:browser_download_url %)) *in*)' +bb '(-> first :assets)' | +bb '(some #(re-find #".*linux.*" (:browser_download_url %)) )' "https://github.com/borkdude/babashka/releases/download/v0.0.4/babashka-0.0.4-linux-amd64.zip" ``` @@ -631,7 +631,7 @@ Contributed by [@plexus](https://github.com/plexus). ``` shellsession $ curl https://clojars.org/stats/all.edn | -bb -o '(for [[[group art] counts] *in*] (str (reduce + (vals counts)) " " group "/" art))' | +bb -o '(for [[[group art] counts] ] (str (reduce + (vals counts)) " " group "/" art))' | sort -rn | less 14113842 clojure-complete/clojure-complete @@ -684,7 +684,7 @@ Contributed by [@plexus](https://github.com/plexus). ``` shellsession $ cat project.clj | sed -e 's/#=//g' -e 's/~@//g' -e 's/~//g' | -bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 *in*))] +bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 ))] {:paths (into source-paths resource-paths) :deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))}) ' | jet --pretty > deps.edn diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 184aaff2..69c50b8e 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -137,12 +137,12 @@ (println " --help, -h or -? Print this help text. --version Print the current version of babashka. - -i Bind *in* to a lazy seq of lines from stdin. - -I Bind *in* to a lazy seq of EDN values from stdin. + -i Bind to a lazy seq of lines from stdin. + -I Bind to a lazy seq of EDN values from stdin. -o Write lines to stdout. -O Write EDN values to stdout. --verbose Print entire stacktrace in case of exception. - --stream Stream over lines or EDN values from stdin. Combined with -i or -I *in* becomes a single value per iteration. + --stream Stream over lines or EDN values from stdin. Combined with -i or -I becomes a single value per iteration. -e, --eval Evaluate an expression. -f, --file Evaluate a file. -cp, --classpath Classpath to use. @@ -175,14 +175,14 @@ Everything after that is bound to *command-line-args*.")) (defn start-repl! [ctx read-next] (let [ctx (update ctx :bindings assoc - (with-meta '*in* + (with-meta ' {:sci/deref! true}) (read-next))] (repl/start-repl! ctx))) (defn start-socket-repl! [address ctx read-next] (let [ctx (update ctx :bindings assoc - (with-meta '*in* + (with-meta ' {:sci/deref! true}) (read-next))] (socket-repl/start-repl! address ctx) @@ -294,7 +294,7 @@ Everything after that is bound to *command-line-args*.")) (let [expr (if file (read-file file) expression)] (if expr (loop [in (read-next *in*)] - (let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '*in* + (let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta ' (when-not stream? {:sci/deref! true})) in)] (if (identical? ::EOF in) diff --git a/test/babashka/impl/repl_test.clj b/test/babashka/impl/repl_test.clj index 8adbde77..dfe49c74 100644 --- a/test/babashka/impl/repl_test.clj +++ b/test/babashka/impl/repl_test.clj @@ -7,7 +7,7 @@ (set! *warn-on-reflection* true) (defn repl! [] - (start-repl! {:bindings {(with-meta '*in* + (start-repl! {:bindings {(with-meta ' {:sci/deref! true}) (delay [1 2 3]) '*command-line-args* @@ -27,7 +27,7 @@ (assert-repl "1\n(dec *1)(+ *2 *2)" "2") (assert-repl "1\n(dec *1)(+ *2 *2)" "2") (assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]") - (assert-repl "*in*" "[1 2 3]")) + (assert-repl "" "[1 2 3]")) ;;;; Scratch diff --git a/test/babashka/impl/socket_repl_test.clj b/test/babashka/impl/socket_repl_test.clj index 085561dd..ad04df74 100644 --- a/test/babashka/impl/socket_repl_test.clj +++ b/test/babashka/impl/socket_repl_test.clj @@ -31,7 +31,7 @@ (deftest socket-repl-test (try (if tu/jvm? - (start-repl! "0.0.0.0:1666" {:bindings {(with-meta '*in* + (start-repl! "0.0.0.0:1666" {:bindings {(with-meta ' {:sci/deref! true}) (delay [1 2 3]) '*command-line-args* @@ -47,8 +47,8 @@ (sh "bash" "-c" "lsof -t -i:1666")))))) (is (socket-command "(+ 1 2 3)" "user=> 6")) - (testing "*in*" - (is (socket-command "*in*" "[1 2 3]"))) + (testing "" + (is (socket-command "" "[1 2 3]"))) (testing "*command-line-args*" (is (socket-command '*command-line-args* "\"a\" \"b\" \"c\""))) (testing "&env" @@ -72,7 +72,7 @@ (dotimes [_ 1000] (t/run-tests)) (stop-repl!) - (start-repl! "0.0.0.0:1666" {:bindings {(with-meta '*in* + (start-repl! "0.0.0.0:1666" {:bindings {(with-meta ' {:sci/deref! true}) (delay [1 2 3]) '*command-line-args* diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index ae9af243..492bd252 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -34,45 +34,45 @@ (deftest main-test (testing "-io behaves as identity" - (= "foo\nbar\n" (test-utils/bb "foo\nbar\n" "-io" "*in*"))) + (= "foo\nbar\n" (test-utils/bb "foo\nbar\n" "-io" ""))) (testing "if and when" - (is (= 1 (bb 0 '(if (zero? *in*) 1 2)))) - (is (= 2 (bb 1 '(if (zero? *in*) 1 2)))) - (is (= 1 (bb 0 '(when (zero? *in*) 1)))) - (is (nil? (bb 1 '(when (zero? *in*) 1))))) + (is (= 1 (bb 0 '(if (zero? ) 1 2)))) + (is (= 2 (bb 1 '(if (zero? ) 1 2)))) + (is (= 1 (bb 0 '(when (zero? ) 1)))) + (is (nil? (bb 1 '(when (zero? ) 1))))) (testing "and and or" - (is (= false (bb 0 '(and false true *in*)))) - (is (= 0 (bb 0 '(and true true *in*)))) - (is (= 1 (bb 1 '(or false false *in*)))) - (is (= false (bb false '(or false false *in*)))) - (is (= 3 (bb false '(or false false *in* 3))))) + (is (= false (bb 0 '(and false true )))) + (is (= 0 (bb 0 '(and true true )))) + (is (= 1 (bb 1 '(or false false )))) + (is (= false (bb false '(or false false )))) + (is (= 3 (bb false '(or false false 3))))) (testing "fn" - (is (= 2 (bb 1 "(#(+ 1 %) *in*)"))) + (is (= 2 (bb 1 "(#(+ 1 %) )"))) (is (= [1 2 3] (bb 1 "(map #(+ 1 %) [0 1 2])"))) - (is (= 1 (bb 1 "(#(when (odd? *in*) *in*))")))) + (is (= 1 (bb 1 "(#(when (odd? ) ))")))) (testing "map" (is (= [1 2 3] (bb 1 '(map inc [0 1 2]))))) (testing "keep" (is (= [false true false] (bb 1 '(keep odd? [0 1 2]))))) (testing "->" - (is (= 4 (bb 1 '(-> *in* inc inc (inc)))))) + (is (= 4 (bb 1 '(-> inc inc (inc)))))) (testing "->>" - (is (= 10 (edn/read-string (test-utils/bb "foo\n\baar\baaaaz" "-i" "(->> *in* (map count) (apply max))"))))) + (is (= 10 (edn/read-string (test-utils/bb "foo\n\baar\baaaaz" "-i" "(->> (map count) (apply max))"))))) (testing "literals" (is (= {:a 4 :b {:a 2} :c [1 1] :d #{1 2}} - (bb 1 '{:a (+ 1 2 *in*) - :b {:a (inc *in*)} - :c [*in* *in*] - :d #{*in* (inc *in*)}})))) + (bb 1 '{:a (+ 1 2 ) + :b {:a (inc )} + :c [ ] + :d #{ (inc )}})))) (testing "shuffle the contents of a file" (let [in "foo\n Clojure is nice. \nbar\n If you're nice to clojure. " in-lines (set (str/split in #"\n")) out (test-utils/bb in "-io" - (str '(shuffle *in*))) + (str '(shuffle ))) out-lines (set (str/split out #"\n"))] (is (= in-lines out-lines)))) (testing "find occurrences in file by line number" @@ -80,14 +80,14 @@ (-> (bb "foo\n Clojure is nice. \nbar\n If you're nice to clojure. " "-i" - "(map-indexed #(-> [%1 %2]) *in*)") - (bb "(keep #(when (re-find #\"(?i)clojure\" (second %)) (first %)) *in*)")))))) + "(map-indexed #(-> [%1 %2]) )") + (bb "(keep #(when (re-find #\"(?i)clojure\" (second %)) (first %)) )")))))) (deftest println-test (is (= "hello\n" (test-utils/bb nil "(println \"hello\")")))) (deftest input-test - (testing "bb doesn't wait for input if *in* isn't used" + (testing "bb doesn't wait for input if isn't used" (is (= "2\n" (with-out-str (main/main "(inc 1)")))))) (deftest System-test @@ -114,12 +114,12 @@ (is (re-find #"doctype html" resp)))) (deftest stream-test - (is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc *in*)"))) - (is (= "2\n3\n4\n" (test-utils/bb "{:x 2} {:x 3} {:x 4}" "--stream" "(:x *in*)"))) + (is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc )"))) + (is (= "2\n3\n4\n" (test-utils/bb "{:x 2} {:x 3} {:x 4}" "--stream" "(:x )"))) (let [x "foo\n\bar\n"] - (is (= x (test-utils/bb x "--stream" "-io" "*in*")))) + (is (= x (test-utils/bb x "--stream" "-io" "")))) (let [x "f\n\b\n"] - (is (= x (test-utils/bb x "--stream" "-io" "(subs *in* 0 1)"))))) + (is (= x (test-utils/bb x "--stream" "-io" "(subs 0 1)"))))) (deftest load-file-test (let [tmp (java.io.File/createTempFile "script" ".clj")] @@ -145,21 +145,21 @@ (deftest pipe-test (when test-utils/native? (let [out (:out (sh "bash" "-c" "./bb -o '(range)' | - ./bb --stream '(* *in* *in*)' | + ./bb --stream '(* )' | head -n10")) out (str/split-lines out) out (map edn/read-string out)] (is (= (take 10 (map #(* % %) (range))) out)))) (when test-utils/native? (let [out (:out (sh "bash" "-c" "./bb -O '(repeat \"dude\")' | - ./bb --stream '(str *in* \"rino\")' | - ./bb -I '(take 3 *in*)'")) + ./bb --stream '(str \"rino\")' | + ./bb -I '(take 3 )'")) out (edn/read-string out)] (is (= '("duderino" "duderino" "duderino") out))))) (deftest lazy-text-in-test (when test-utils/native? - (let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 *in*)'")) + (let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 )'")) out (edn/read-string out)] (is (= '("y" "y") out)))))