This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-14
Channels
- # announcements (3)
- # aws (7)
- # babashka (108)
- # beginners (222)
- # bristol-clojurians (3)
- # calva (8)
- # chlorine-clover (1)
- # cider (14)
- # clj-kondo (4)
- # cljdoc (6)
- # cljs-dev (89)
- # cljsrn (13)
- # clojars (6)
- # clojure (89)
- # clojure-australia (1)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-losangeles (11)
- # clojure-nl (6)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (9)
- # clojurescript (47)
- # conjure (18)
- # datomic (7)
- # docker (1)
- # figwheel (43)
- # figwheel-main (2)
- # fulcro (31)
- # kaocha (3)
- # leiningen (7)
- # luminus (2)
- # nrepl (14)
- # off-topic (24)
- # pathom (5)
- # pedestal (5)
- # rdf (4)
- # re-frame (49)
- # reagent (12)
- # reitit (9)
- # rum (21)
- # shadow-cljs (109)
- # tools-deps (35)
- # vim (8)
- # wasm (1)
quick question. Some of my babashka scripts need to deal with complex xml data structures and doing this directly via clojure/data.xml
which is included in bb can be somewhat painful. In other words, I would like to use clojure.data.zip.xml
namespace and specifically the xml-zip
function. I tried adding org.clojure/data.zip
to the classpath using add-classpath
, this seems to work but then when requiring clojure.data.zip.xml
which in turn requires clojure.data.zip
which in turn requires clojure.zip
I get an exception saying:
Could not require clojure.zip. [at clojure/data/zip.clj, line 11, column 1]
but is not clojure.zip
supposed to be part of clojure? i.e. already bundled into babashka?
As a side note I find the name space naming and package dependency setup with clojure.zip
vs clojure.data.zip
et al somewhat unfortunate and confusing. Maybe this is where I fell off the trail?but in jvm clojure clojure.zip
is part of clojure and not a separate dependency right?
well it's not all automatically using clojure core on the JVM and that's it, it takes a little more work sometimes
and clojure.zip has never been requested before - I'm generally adding stuff by request or stuff I'm using myself already
I actually ended up writing my own (defn xml-> [d & fns]...)
because I got tired of navigating all the :tag
and :content
stuff returned from xml parse, but yeah, would be nice not to reinvent the weel
@mbjarland take a look at babashka.impl.xml
and then do the same for clojure.zip
under babashka.impl.clojure.zip
also take a look at https://github.com/borkdude/babashka/blob/master/doc/dev.md how to get started (git pull recursive)
not sure if clojure.zip
strictly speaking belongs under xml as I think zippers can be used for other things though
clojure.zip is just some pure functions, that doesn't take up a lot of space. xml does because of the dependency on all kinds of Java stuff
we can also measure the difference in binary size as reported in #babashka_circleci_builds
including a comment which lets us know that Rich still runs on a macbook:
(comment
(load-file "/Users/rich/dev/clojure/src/zip.clj")
(refer 'zip)
ok so where does that leave us, not in sci, not as a feature but rather directly into bb
yes. just like tools.cli, http://clojure.java.io, etc.
I think pods might take the place of feature flags eventually, but only time will tell
There is an issue about data-readers if anyone wants to chime in with some insights: https://github.com/borkdude/babashka/issues/419
Hello. Please excuse my ignorance, but is there any way to pretty-print the result of running an expression in sci from JavaScript? I recognise that I could probably achieve this if I had used ClojureScript and then bound the clojure.pprint function to a function inside sci. I'm thinking about embedding sci in my Gatsby blog to enable interactive Clojure-snippets.
@snorremd clojure.pprint
isn't part of the default sci library, but as you say you can bind it yourself and then compile to a JS target
Right, I suspected so. Thank you for the quick answer and for creating sci. Will have fun playing with it.
Note that you will have to bind *out*
to sci/out
. similar to this: https://github.com/borkdude/babashka/blob/79cba0fbef1d9bb39f2db470dfca0024fd42afb0/src/babashka/impl/clojure/pprint.clj#L26
@snorremd There is also documentation available here: https://borkdude.github.io/sci/doc/codox/sci.core.html
Will definitely take a closer look at the documentation. Now the hard part is only figuring out the cljs compilation and bundling in gatsby pipeline. But this should get me going on the sci part at least. 👍 Thank you again.
@snorremd Take a look at script/compile-js
and script/release-js
. It's relatively straightforward.
The javascript API may be a bit behind the CLJS api, feel free to comment on that if you need anything
@snorremd I had to take a look myself as well, the main gist of it is in min.js.edn
which is used in a CLJS setting
Yeah, I read a post by David Nolen that suggests as much: https://clojurescript.org/guides/webpack.
Hi! Saw you retweeted my tweet about interactive clojure support via sci. Just wanted to let you know I solved the pretty-printing thing by making my own clojurescript namespace wrapping sci cwith some minimal stuff like catching exceptions and pretty-printing the results. See the code here: https://github.com/snorremd/snorreio/blob/master/src/cljs/sci_wrapper.cljs
Essentially I tried bundling the minified version of my wrapper with and without the new bundle option in clojurescript compiler. But it seems that no matter you get compiled output that webpack in Gatsby don't like. So for JavaScript + webpack projects simply serving the compiled and optimized clojurescript as a static file and using ugly side-effecting script loading in react should work. 👍
It works considering it exposes sci as a commonjs module, but webpack (at least with the default bundling settings) consumes so much resources that at least github actions ran out of memory.
@snorremd If you want to capture output from prn
etc, you could include this:
(let [sb (goog.string/StringBuffer.)] (sci/binding [sci/out sb] [(sci/eval-string "(do (prn :foo) 1)") (str sb)]))
[1 ":foo\n"]
@snorremd the cljs version should do all of the things the clj version can do if you remain in the clojure domain. That was my experience at least. Only when you go crazy on interop you might find some edge cases (https://github.com/borkdude/sci/pull/286)
@borkdude I made a small tweak to your Sci playground to add datascript https://jeroenvandijk.github.io/sci.web/?gist=jeroenvandijk/25f841d07f8faf6b2488060e16fc6ae7
I’ll not keep it under my name, but it’s to show others this possibility
Maybe it makes sense to extend this playground with cool libraries such as Datascript and others. So people have a webtool?
Other interesting libraries Meander, core logic, a lot more? If it’s Clojurescript, I think they could also be integrated with Sci, right?
Clojure Toolbox, live in your browser? 🙂
Can we have pods for Sci clojurescript? 🙌 hahah
FYI @borkdude I added a pr for clojure.zip including library support for clojure.data.zip
@mbjarland Wouldn’t that be useful at Sci level? Isn’t jvm specific right?
we had a chat about that above with @borkdude - he seemed to want to leave it outside of sci for now. I’m agnostic, just want access to the clojure.data.zip.xml goodies
ok makes sense, I was just curious
I’m a bit (too?) enthusiastic about the Sci repl now
16:16 borkdude then maybe it should belong in sci... not sure...
16:17 mbjarland seems to be yes
16:17 borkdude I don't think I've ever used it in CLJS though
16:18 let's just not add it there yet
but I agree, it’s pure functions all the way so would not be a problem adding/moving itmakes sense to wait i guess
yeah, I have less than perfect visibility into the sci project and/or the reasoning for the above. I’m happy to change the pr or create a new one if we want it moved
@jeroenvandijk Feel free to make a PR with datascript and add the gist to the example list at the bottom
cool, any preference for structure?
or shall i just start adding and wait for feedback 🙂
@mbjarland cool, merged!
@jeroenvandijk pods for CLJS: I think that is possible. the pod lib already supports the JVM. CLJS support can be added there as well. nREPL also works from JS based editors, so I don't see why it wouldn't work for pods
it would be BIG 🙂
think observablehq for clojurescript
Load any clojurescript library directly in your browser
ok i’ll think about it how this can work if you don’t beat me to it 🙈
haha np, I’ll show you the power of your pods 😅
@mbjarland btw if you need a binary without building yourself, they are available pre-release in #babashka_circleci_builds
One issue I want to solve before a next release is the following one: https://github.com/borkdude/babashka/issues/419#issuecomment-628671008 So the loading of data reader functions. The problem is: it's technically possible, but scanning an entire classpath at the start of each script may waste some startup time (8-15ms).