This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-18
Channels
- # announcements (17)
- # babashka (109)
- # beginners (212)
- # calva (1)
- # chlorine-clover (7)
- # cider (8)
- # clj-kondo (31)
- # cljsrn (2)
- # clojure (33)
- # clojure-dusseldorf (1)
- # clojure-finland (2)
- # clojure-france (22)
- # clojure-germany (1)
- # clojure-losangeles (1)
- # clojure-spec (6)
- # clojure-uk (19)
- # clojurescript (31)
- # conjure (41)
- # cryogen (1)
- # data-science (11)
- # datomic (6)
- # emacs (5)
- # exercism (8)
- # figwheel-main (2)
- # fulcro (57)
- # graalvm (15)
- # hoplon (15)
- # jobs-discuss (32)
- # kaocha (7)
- # off-topic (14)
- # pathom (2)
- # planck (9)
- # quil (1)
- # rum (5)
- # shadow-cljs (34)
- # spacemacs (33)
- # tools-deps (1)
- # xtdb (9)
now that babashka has an nrepl, which editor would ppl here recommend for interactively developing bb scripts? i saw chlorine claims to provide support for it: https://mauricio.szabo.link/blog/2020/04/01/nrepl-on-chlorine/ anything else?
You can also do that using socket repl, chlorine was originally built for socket repl. I'm using it from 6 months and it works great.
shell$ bb --socket-repl 8990
using it with chlorine? any downsides? are you missing any features you would get from an nrepl client?
just for the record, Cursive nREPL client gives this error, btw:
Connecting to remote nREPL server...
clojure.lang.ExceptionInfo: Unable to resolve classname: java.lang.reflect.Method [at line , column ]
Error initialising completion
Error initialising locals clearing:
clojure.lang.ExceptionInfo: Could not resolve symbol: *compiler-options* [at line 1, column 6]
clojure.lang.ExceptionInfo: Could not resolve symbol: clojure.core/clojure-version [at line 1, column 57]
Error initialising REPL:Error updating completions:
clojure.lang.ExceptionInfo: Could not resolve symbol: cursive.repl.runtime/completions [at line 1, column 2]
Yes, I use repl to evaluate and redefine functions. It simply works.
i have kinda settled with intellij+cursive for now, when it comes to clj development, but in our small company, practically everyone uses a different editor and they are quite keen on staying with it. since im the clojure advocate in the company, i have the ungrateful job of learning all the editors and their clojure toolings, so i can ensure that my colleagues clojure journey is as gelled as possible 🙂
I just use it to evaluate expressions and for interactive development. It provides basic auto completion. Although you can use more advanced features. Read readme.md of Atom Chlorine. I came from emacs and am quite satisfied with experience.
we literally have users of all these editors: - 1 intellij (myself) - 1 (neo)vim (the other most experienced programmer) - 1 spacemacs on macos (also quite experienced programmer, but mostly working as a CTO) - 1 spacemacs on linux (nixos) (also experienced ex-physicist coder) - 2-3 vs code (frontend devs) - 1 atom (junior data scientist)
which atom version are u on? stable/beta/nightly? im just asking because something was complaining about the version of the ink package i need to use; had to manually downgrade it or something...
I'm on stable version. You can join #chlorine channel to interact with developers and users of chlorine.
could have been just an issue with https://github.com/dvcrn/proton though... which seems to be a quite promising project. it's really similar to spacemacs, which im a bit envious of, while i would really prefer the performance of doom-emacs 🙂
for the record, Curisve just gets stuck at
Connecting to remote Socket REPL...
when im trying to connect to a bb --socket-repl
Emacs is great, but sometimes it's overwhelming for me. And it distracts me. So, I'm staying with Chlorine and Atom.
@U086D6TBN Documentation on editors + REPLs is here: https://github.com/borkdude/babashka/blob/master/doc/repl.md
Ah, thx. I just searched for "editor" within the main readme but haven't found anything. since that readme is so long, i just assumed that's all the available documentation for babashka
I added the word editor here now: https://github.com/borkdude/babashka/#running-a-repl
I use Emacs with Cider and it works great.
Cool! What’s next? 😅💪
hello, is there a recommended library to parser XML with babashka?
@wilkerlucio co-incidentally, I was just checking on: https://github.com/borkdude/babashka/issues/153
I want to make sure it also works with jdk11. I had to add these classes to the reflection config:
com.sun.xml.internal.stream.XMLInputFactoryImpl
{:methods [{:name "<init>" :parameterTypes []}]}
com.sun.xml.internal.stream.XMLOutputFactoryImpl
{:methods [{:name "<init>" :parameterTypes []}]}
which makes me a bit uncertain about adding it, since these classes are private and may disappear at one point. But if they still work in jdk11, maybe it's fineSeems to still work!
user=> (let [xml (xml/parse-str "<items><item>1</item><item>2</item></items>")] (xml/emit-str xml))
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><items><item>1</item><item>2</item></items>"
user=> (System/getProperty "java.version")
"11.0.6"
@wilkerlucio So, wanna test?
@borkdude hehe, interesting, and sure, I would like to test, just use from master?
@wilkerlucio Check #babashka_circleci_builds. New binaries just got published there from the clojure.data.xml branch
This library has been on the list for a while, I think it makes sense to add it after some people have proven that it works in their scripts
@wilkerlucio Let me know about your success or failures when you're done ok?
@borkdude cool, I got it to work for my case! 😄
its a simple bb
script to extract project version from pom.xml
:
#!/usr/bin/env bb
(defn xml-seq [path]
(->> (xml/parse-str (slurp path))
(tree-seq :content :content)))
(defn tag-name? [tag tname]
(some-> tag :tag name #{tname}))
(defn tag-content-str [tag]
(->> tag :content (filter string?) (str/join "")))
(defn pom-version
([] (pom-version "pom.xml"))
([path]
(->> (xml-seq path)
(filter #(tag-name? % "version"))
first
tag-content-str)))
(println
(pom-version))
so awesome to get this to run so fast, in clojure, I really appreciate babashka work, and your great support 🙏
$ lein pom
Wrote /Users/borkdude/Dropbox/dev/clojure/babashka/pom.xml
$ /tmp/pom.clj
0.0.87-SNAPSHOT
Cool, yeah, it worked 🙂@wilkerlucio Added your example to the tests and also as an example to the README: https://github.com/borkdude/babashka/tree/clojure.data.xml#pomxml-version
@borkdude I'm thinking here about scripting dependencies, have you consider at some point allowing scripts to load code direct from the internet/path, I'm thinking on this way:
(require
[""
:as pom])
(println (pom/pom-version))
I imagine this could be nice, if babashka could load and cache, and use the URL itself as internal name for the NS, kinda like nodejs works on file system.
The first concern is of course security, given a URL content can change anytime, to aleviate that I was thinking on constraining the URL's for things we know wont change, for example raws from github with a commit SHA present, kind a crazy idea, but wonder what you think about it@wilkerlucio I have been thinking about that. The closest you can get to that right now as as follows: https://github.com/borkdude/clojure-toolbox.com-babashka/blob/5b516fa0e325b7c9ba973a88e4600d3bbad97c66/script/generate.clj#L11-L26
I'm hesitant about introducing something like that because dependency resolution is a tricky thing and I rather leave that to tools like tools.deps, etc.
you can just download the file with babashka.curl or otherwise and load it with load-file
as well
or use slurp
+ load-string
.
yeah, I understand, it just feels very tempting 😛
maybe a middle ground solution would be to allow the declaration of clojure deps on the script itself?
#!/usr/bin/env bb
(include-deps
{com.wsscode/babashka-tools {:git/url ""
:sha "..."}})
(require ['com.wsscode/babashka-tools :as bbt])
@wilkerlucio This is now possible:
(ns setup
(:require [clojure.java.shell :refer [sh]]
[babashka.classpath :as cp]))
(def deps '{:deps {medley {:mvn/version "RELEASE"}}})
(def cp (-> (sh "clojure" "-Sdeps" (str deps) "-Spath") :out))
(cp/add-classpath cp)
(ns script
(:require [medley.core :refer [index-by]]))
(index-by :a [{:a 1} {:a 2}]) ;; => {1 {:a 1}, 2 {:a 2}}
yeah, just saw that in docs, pretty cool, to turn that in a special "require" seems quite easy
I'm trying to port some perl code that uses the $/
/`$RS` variable for line-based iteration (eg, while (<$fh>) { ... }
) to babashka, but it doesn't look like the jvm offers any such override; just NL/CR. Is there a good workaround for this?
@penryu I'm not sure what this all means 🙂 Typically you iterate over lines with line-seq
or (clojure.string/split s #"\n")
Yeah, sorry for pasting p$r1 c0d$ with wild abandon. The str/split
approach gives me the desired output. However, in this script s
is the contents of a potentially huge file I'm trying to avoid slurping.
Oh, let me clarify: I'm looking for way to change the separator from
\n` to ===\n
so I can process text like
multiple
lines
===
some
more
===
Hrm. true, ===
does work with that. Now I'm not sure how to reassemble "multiple\n"
and "lines\n"
back into "multiple\nlines\n"
... maybe something like partition-by
?
Something like this might work:
(ns lines
(:require [ :as io]
[clojure.string :as str]))
(with-open [r (io/reader "/tmp/foo.txt")]
(doall
(keep #(when-not (= "===" (first %))
(str/join "\n" %))
(partition-by #(= "===" %) (line-seq r)))))
("multiple\nlines" "some\nmore")
i'm working on adding support for bb
in inf-clojure
. Is there a good way for tooling to know its in a Clojure repl powered by bb
rather than clojure
? Normally there is some kind of repl ns that is unique like lumo.repl
or planck.repl
. The only think i can think of right now for bb
is #?(:bb :bb :default :not-bb)
it would be convenient if clojure had something like partition-by
that skipped the separator
@dpsutton bb also has a namespace called babashka.classpath
which is probably not present in any JVM environments, unless someone is going to use babashka as a library, which seems unlikely
@penryu This might be faster using transducers, less garbage:
(ns lines
(:require [ :as io]
[clojure.string :as str]))
(with-open [r (io/reader "/tmp/foo.txt")]
(into []
(comp (partition-by #(= "===" %))
(filter #(not= "===" (first %)))
(map (partial str/join "\n")))
(line-seq r)))
bb is not interested in macroexpansion right? out of scope? (just seeing which features the bb path of inf-clojure needs to support)
(macroexpand '(doseq [x (range 2)] (prn :x)))
doesn't seem to match what clj
does with it
@dpsutton yeah, doseq
is kind of a special built-in thing in bb, that's why not all macroexpanions look the same
yeah, there are a few of those. if it's important I could make it look the same but so far it didn't seem like a big deal 😉
but i think its the difference between clj
and clojure
. in planck and lumo you specify -d
for "dumb terminal"
@dpsutton the behavior of the bb repl is pretty similar to clojure
. i.e. if you don't use rlwrap
, it sucks 😉
the code for the socket repl and repl are pretty much directly borrowed from clojure itself though
inf-clojure can work with a socket repl or just interact with the dumb repl run in emacs itself
bb didn't have vars with docstrings in the beginning and cheshire was there very early on. fixing this is easy though
because the dumb one inf-clojure can just crank up on its own. emacs runs bb
as a subprocess and makes it easy to get editing. if i run it as a socket repl i presumably start it up in a terminal and then connect from emacs
How taboo is it to use def
s inside let
? E.g., minimal example,
(let [HOME (System/getenv "HOME")]
(def bashrc (str HOME "/.bashrc"))
(def zshrc (str HOME "/.zshrc")))