This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-17
Channels
- # adventofcode (23)
- # announcements (2)
- # aws (11)
- # babashka (181)
- # beginners (59)
- # chestnut (2)
- # clj-kondo (9)
- # clojure (90)
- # clojure-brasil (2)
- # clojure-europe (18)
- # clojure-italy (24)
- # clojure-nl (9)
- # clojure-spec (3)
- # clojure-uk (28)
- # clojured (4)
- # clojuredesign-podcast (3)
- # clojurescript (12)
- # community-development (49)
- # core-async (49)
- # cryogen (5)
- # cursive (16)
- # data-science (1)
- # datascript (7)
- # datomic (54)
- # defnpodcast (4)
- # events (2)
- # figwheel-main (14)
- # fulcro (139)
- # graphql (1)
- # jobs-discuss (6)
- # kaocha (1)
- # luminus (2)
- # malli (3)
- # music (1)
- # off-topic (34)
- # pathom (24)
- # re-frame (13)
- # reitit (5)
- # shadow-cljs (8)
- # test-check (6)
$ lein bb examples/process-builder.bb
Syntax error (ClassNotFoundException) compiling at (babashka/impl/classes.clj:91:16).
java.lang.UNIXProcess$ProcessPipeOutputStream
Full report at:
/tmp/clojure-8153440468259675917.edn
$ java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)
There is an issue for JDK 11 here: https://github.com/borkdude/babashka/issues/120 I'll need to make a custom version of clojure.lang.Reflector for it
Do you think Windows support would be easier on JDK11? I don't see a pressing need to upgrade to it right now. I also feel the support for it is more experimental in GraalVM, but I'm not sure
i'm really not sure about the first question. it's clear that there are various fixes and features in java 11 that aren't in java 8 though (e.g. some process support) i agree support for windows is more experimental in graalvm. it seems like windows support lagging is almost inevitable for some multiplatform efforts because of all of these odd limitations and behaviors in the os. i think if it isn't too much work, exercising some of the jdk11 bits is good because we can: 1) have a better idea of what some upcoming issues might be (like this unixprocess thing) 2) possibly file issues to get stuff fixed sooner (so things will be in place for us later)
I tried to use dotimes, like this bb '(dotimes [i 10] (println i))'
, but I got Could not resolve symbol: i [at line 1, column 11]
. Is dotimes not available? How do I know what is and what isn't available?
@steveb8n How would you do base64 in normal Clojure? Maybe I could add support for those classes/functions
the simplest is interop
(:import (java.util Base64 UUID))
(.decode (Base64/getDecoder) s)
but there’s also https://clojure.github.io/data.codec/
I was gonna try and figure out the dep/require but in this case I’ll wait till it’s built in
First step would be adding support for the raw Java class:
$ clj -e '(-> (java.util.Base64/getDecoder) (.decode "YmFiYXNoa2E=") (String.))'
"babashka"
I'll give it a tryit seems data.codec is from before a certain Java version since they don't use this?
@steveb8n Note that you can already do this today:
$ bb '(:out (shell/sh "base64" "-D" :in "YmFiYXNoa2E="))'
"babashka"
Still, some things are not available, like ns-interns
. Is there a list of everything available somewhere?
The README lists some difference with Clojure. Everything related to vars and namespaces is re-implemented.
So the result of ns-interns
would be different than in Clojure right now. But it seems most people are just interested in the keys, not the values?
I just wanted to see what exactly is missing, and tried to use ns-functions to do it.
Trying to figure out what the differences are between joker and babashka too. They seem pretty similar.
@oskarkv I guess I could just make ns-interns
and fake the values by printing them as vars 😉
As for the differences between joker and babashka: I think joker is more mature, since it has been around longer, babashka is still in active development. Also it tries to be more compatible with Clojure by not introducing custom namespaces, so when babashka is not enough, you can just run the JVM without major changes
And there's the bash integration like:
$ bb -o '(range)' | bb -io '(take 3 *in*)'
0
1
2
Yeah, that's nice. Tried to do the same thing with joker just now but couldn't figure it out. But maybe that's just me. 😛
babashka also allows interop with a curated set of Java classes, which is another difference
I don't know if the docs are up to date, but they are listed here as well: https://github.com/borkdude/babashka/blob/master/reflection.json
I'm going to add support for more Java classes as we progress (e.g. the Base64 class that Steve requested above)
The conch low level namespace will no longer be supported in babashka, now that there will be direct support for ProcessBuilder
:
https://github.com/borkdude/babashka#spawning-and-killing-a-process
@sogaiu This now works on master:
#!/usr/bin/env bb
(require '[babashka.wait :as wait])
(def ws (-> (ProcessBuilder. ["python" "-m" "SimpleHTTPServer" "1777"]) (.inheritIO) (.start)))
(wait/wait-for-port "localhost" 1777)
(prn (slurp ""))
(.destroy ws)
Note that I had to make a fix for wait/wait-for-port and close the Socket, since it seems that SimpleHTTPServer is single threaded 🙂@sogaiu We might add a PYTHON_CMD
environment variable to fix your python2 issues with the tests
since python isn't likely to be on windows machines by default, i think switching over to using some jvm-based web server like you mentioned before is a better idea.
Hm, say I have a library that has reader conditionals for cljs and clj that I also want to use in babashka, and the clj part would work in babashka. Then I could use :default instead of :clj, and when there is only :clj (no :cljs) I could use :default and add a :cljs nil
. Or is there an easier way?
Yeah but if the clj code works in bb too, adding :bb would mean copying the code, right?
if clojure itself supported something like #?(#{:clj :bb} 1 :cljs 2)
this would become easier, but it doesn't
@borkdude Or maybe you could make it so that if a reader conditional has only :clj
and :cljs
, then bb uses the :clj
one, but if it has :bb
, then of course use that. Would that make sense? 🙂
I don't think that works, since the reader conditional processing is done by a parser library which you give the features in advance
what would be the current recommendation for converting HTML to Hiccup from the command line?
(and I see another reason why I should maybe just include a link to bootleg instead of baking html support into jet)
someone else wanted to bring the conversion functionality into a clojure project. Will look at getting it up to clojars as a library next release
so would be something like bootleg -d -e '(convert-to *in* :hiccup)' <<< '<html></html>'
Promotional tweet: https://twitter.com/borkdude/status/1206937471461797888
@retrogradeorbit How does one get from a literal string to hiccup right now?
./bootleg -d -e '"<html></html>"'
so tl;dr:
$ bootleg -d -e '(html "<div><h1>heading</h1><p>body</p></div>" :data :hiccup)'
[:div {} [:h1 {} "heading"] [:p {} "body"]]
This is great, thanks @retrogradeorbit and @borkdude. And another tool in the clojure+graal space to add my tool belt :)
reading from *in*
would be great, as well as cleaning up the hiccup (removing the empty property maps, also I don't know if you already roll classes/id into the keyword)
Im not actually generating the markup. so the {}
are a relic of the downstream converters
there is some magic that I need to do to get those converters to behave. they are a little, um, warty?
clojure.walk is exposed inside bootleg. let me see if I can hack them out on the command line...
bootleg -d -e '(->> (html "") (clojure.walk/postwalk #(if (and (vector? %) (= {} (second %))) (vector (concat [(first %)] (subvec % 2))) %)))'
I don't need it right now so don't do it for me 🙂 just thinking out loud that it would be nice.
since I think converting to Hiccup will mainly be used when people want to copy some outside example into their code
I have used a webservice for that before, e.g. http://html2hiccup.buttercloud.com
here's another one: https://htmltohiccup.herokuapp.com/
and I think Cursive does it now as well, when you paste HTML into Clojure (never tried it)
emacs does it too, I actually wrote the package for that. But CLI tools can be used by anyone regardless of their editor.
cat project.clj | bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 *in*))] {:paths (into source-paths resource-paths) :deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))} ) ' | jet --pretty > deps.edn
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*))] {:paths (into source-paths resource-paths) :deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))} ) ' | jet --pretty > deps.edn
@plexus without sed
:
$ cat project.clj | bb -io '(str/replace (str/join "\n" *in*) "#=" "")' | bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 *in*))] {:paths (into source-paths resource-paths) :deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))})' | jet --pretty
maybe even nicer:
cat project.clj | bb -io --stream '(str/replace *in* "#=" "")'
yeah, that's fine 🙂$ 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*))]
{:paths (into source-paths resource-paths) :deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))})' |
jet --pretty
a little bit indented etc.