This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-28
Channels
- # announcements (1)
- # babashka (28)
- # beginners (228)
- # cider (9)
- # clara (6)
- # clojure (66)
- # clojure-uk (13)
- # clojuredesign-podcast (5)
- # clojurescript (9)
- # core-typed (1)
- # cursive (1)
- # duct (2)
- # emacs (8)
- # fulcro (18)
- # graalvm (11)
- # hyperfiddle (1)
- # malli (2)
- # off-topic (33)
- # re-frame (9)
- # reagent (3)
- # reitit (15)
- # shadow-cljs (6)
- # tools-deps (1)
@deleted-user as an alternative you can probably build a script which inlines all namespaces into a single file
@deleted-user I've got an experimental thing here: Mac: https://2917-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-macos-amd64.zip Linux: https://2915-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-linux-amd64.zip
$ export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {clj-http-lite {:git/url "" :sha "f44ebe45446f0f44f2b73761d102af3da6d0a13e"}}}' -Spath)"
$ lein bb --uberscript "(require '[clj-http.lite.client :as client]) (:status (client/get \"\"))"
200
This will put all the required namespaces into one single file in /tmp/uberscript.clj
. Now you can:
$ bb /tmp/uberscript.clj
200
How do I truncate a number e.g. 52.51029159197582
to two decimal places e.g. 52.51
in babashka?
e.g. (clojure.pprint/cl-format nil "~,2f" 52.51029159197582)
won't work
@slack.jcpsantiago I think you can do this with format
@deleted-user New version:
$ bb --classpath test-resources/babashka/src_for_classpath_test -m my.main --uberscript /tmp/script.clj
$ bb /tmp/script.clj 1 2 3
("1" "2" "3")
Linux: https://2921-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-linux-amd64.zip
Mac: https://2923-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.51-SNAPSHOT-macos-amd64.zipDemo:
$ # create project sources
$ mkdir -p project/src
$ echo "(ns project-impl) (defn foo [] ::foo)" > project/src/project_impl.clj
$ echo "(ns project-main (:require [project-impl])) (defn -main [& args] (project-impl/foo))\n" > project/src/project_main.clj
$ #
$ # run with bb using classpath
$ bb --classpath project/src -m project-main
:project-impl/foo
$ #
$ # create uberscript
$ bb --classpath project/src -m project-main --uberscript uberscript.clj
$ cat uberscript.clj
(ns project-impl) (defn foo [] ::foo)
(ns project-main (:require [project-impl])) (defn -main [& args] (project-impl/foo))
(ns user (:require [project-main])) (apply project-main/-main *command-line-args*)% $ #
$ # run uberscript
$ bb uberscript.clj
:project-impl/foo
Using deps.clj (https://github.com/borkdude/deps.clj/):
deps.edn: {:aliases {:script {:main-opts ["-m project-main"]}}}
$ deps.exe -A:script -Scommand "bb --classpath {{classpath}} {{main-opts}} --uberscript uberscript.clj"
$ bb uberscript.clj
:project-impl/foo
Note that when you already have babashka on your system, installing deps.clj is trivial:
$ curl -sL -o /tmp/deps.clj && chmod +x /tmp/deps.clj
$ /tmp/deps.clj
Clojure 1.10.1
It only assumes a working java
installation, nothing else.Updated the quickstart, rationale and install sections for deps.clj: https://github.com/borkdude/deps.clj/blob/master/README.md#quickstart
Babashka v0.0.51 released, which adds the --uberscript
option: https://github.com/borkdude/babashka/blob/master/README.md#uberscript
great ideas!
distinct doesn't promise to preserve order. seems to though.
Splitting on (System/getProperty "file.separator")
is recommended for OS portability
Your remove-dups function might come in handy for reporting which entries are duplicates
I made this of it:
(require '[clojure.string :as str])
(defn get-path []
(System/getenv "PATH"))
(defn report-dups
[coll]
(reduce
(fn [acc next]
(if (contains? acc next)
(do
(println "Duplicate PATH entry" next )
acc)
(conj acc next)))
#{}
coll)
nil)
(as-> (get-path) $
(str/split $ (re-pattern (System/getProperty "path.separator")))
(report-dups $))
and it helped me find that have accidentally doubled my entire PATH string somewherenice!