This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-12
Channels
On master, clojure.repl/dir
:
user=> (dir clojure.string)
blank?
capitalize
ends-with?
...
Self-contained script with dependencies:
(ns script
{:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [add-classpath!]}}}}
(:require [clojure.java.shell :refer [sh]]
[ :as io]))
;; set up dependency tool
(when-not (.exists (io/file "/tmp/deps.clj"))
(sh "curl" "" "-o" "/tmp/deps.clj"))
(def medley-dep '{:deps {medley {:git/url ""
:sha "91adfb5da33f8d23f75f0894da1defe567a625c0"}}})
(def cp (:out (sh "bb" "/tmp/deps.clj"
"-Spath"
"-Sdeps" (str medley-dep))))
(add-classpath! cp)
(require '[medley.core :as m])
(m/index-by :id [{:id 1} {:id 2}])
just pushed this to master. feel free to try it out.. not sure if this is the right API, so feedback welcome 🙂
ok, will check it out. coincidentally, i was working on adding a jar to the classpath at runtime in an ordinary clojure project: https://github.com/sogaiu/alc.start-repl/blob/master/src/alc/start_repl/impl/attach.clj
just tried -- here's what i got:
$ ./bb examples/add-classpath.bb
{1 {:id 1}, 2 {:id 2}}
I made a small tweak to the script where it skips downloading if the file already exists
updated the script example to include clj-kondo config to suppress warning for add-classpath!
. should I maybe add this function to a namespace instead of clojure.core
?
oh, I just discovered that *file*
is also an actual thing in clojure
. I thought it was invented by joker
but now I understand why I didn't get a warning about that
so I guess moving add-classpath!
to another namespace makes sense. clojure does have add-classpath
without the exclamation mark, but that's deprecated
Updated version with change on bb master (see #babashka_circleci_builds for downloads)
(ns script
(:require [clojure.java.shell :refer [sh]]
[ :as io]
[babashka.classpath :refer [add-classpath]]))
;; set up dependency tool
(when-not (.exists (io/file "/tmp/deps.clj"))
(sh "curl" "" "-o" "/tmp/deps.clj"))
(def medley-dep '{:deps {medley {:git/url ""
:sha "91adfb5da33f8d23f75f0894da1defe567a625c0"}}})
(def cp (:out (sh "bb" "/tmp/deps.clj"
"-Spath"
"-Sdeps" (str medley-dep))))
(add-classpath cp)
(require '[medley.core :as m])
(m/index-by :id [{:id 1} {:id 2}])